zoukankan      html  css  js  c++  java
  • linux sed命令查询结果前后批量追加内容(html文件批量修改css,js等文件路径)

    1.需求:linux使用shell命令查询结果前后批量追加内容

    例如:我需要在当前目录下所有的css文件路径前追加域名

    我想的是用sed替换去实现,鲍哥的思路是用for循环

    1.1方法1:鲍哥的for循环

    这是鲍哥的思路,我写出来后,鲍哥说很二.

    for i in `find . -type f -name '*.css'`;do echo 'http://www.baidu.com/css/'$i;done

    1.2方法2:sed替换

    find . -type f -name '*.css'|sed -rn 's#(^.*)#'http://www.baidu.com/css/'1#gp'

     

    sed -r 支持正则

    (^.*) 是find查找出来的结果通过管道,传送给sed正则匹配。也就是./icon.css等本地路径

    'http://www.baidu.com/css/'1 这个1就是刚才sed正则(^.*)匹配出来的内容,

    然后可以在前后批量追加你想要的内容。

    命令并不完美,路径中间带点.如果各位客官有更好的命令欢迎留言。

    2.需求:html文件css,js,img等路径批量替换

    例如:我需要在js文件路径前批量添加js目录

    sed -i 's#^(.* src=")(.*.js.*)$#1js/2#g'  文件名

  • 相关阅读:
    luogu 2962 [USACO09NOV]灯Lights
    bzoj 1923
    bzoj 1013
    bzoj 3513
    bzoj 4259
    bzoj 4503
    CF 632E
    bzoj 3527
    bzoj 3160
    bzoj 2179
  • 原文地址:https://www.cnblogs.com/zhanmeiliang/p/6400173.html
Copyright © 2011-2022 走看看