zoukankan      html  css  js  c++  java
  • [linux] 替换字符串

    Linux下批量替换多个文件中的字符串的简单方法。用sed命令可以批量替换多个文件中的字符串。

    命令如下:sed -i “s/原字符串/新字符串/g” `grep 原字符串 -rl 所在目录`

    例如:我要把 charset=gb2312 替换为 charset=UTF-8,执行命令:sed -i “s/charset=gb2312/charset=UTF-8/g” ‘grep charset=gb2312 -rl /www’ 即可。

    如果把文件按竖线"|"或分号";"分割替换成hive的"1"分割

    sed -i 's/|/x1/g;
    s/;/x1/g
    ' a.txt

    把一个[文件目录][类别目录][日期目录]*.tar.gz改成gzip格式,并替换分隔符,换成hive的"1"分割

    for dir in `ls .`
     do
       if [ -d $dir ]
       then
         echo $dir
         cd $dir
    
     for dir in `ls .`
     do
       if [ -d $dir ]
       then
         echo $dir
         cd $dir
         find . -mindepth 1 -name "*.tar.gz" -type f -exec tar -zxvf {} ; -exec rm -rf {} ; 
         find . -mindepth 1 -name "*.*" -type f -exec sed -i 's/|/x1/g;s/;/x1/g' {} ; -exec gzip -r {} ; 
         cd ..
       fi
    done
    
         cd ..
       fi
    done
  • 相关阅读:
    Mybatis中javaType和jdbcType对应关系
    spy日志
    mybatis批量插入和更新
    js打印方案
    js弹窗,父子窗口调用
    extjs4.1
    oracle开启远程连接访问
    javaweb打印
    Leetcode 392.判断子序列
    Leetcode 391.完美矩形
  • 原文地址:https://www.cnblogs.com/linn/p/5711741.html
Copyright © 2011-2022 走看看