Home  >  Q&A  >  body text

linux怎么批量修改文件内容?

linux怎么批量修改文件内容?

比如:
操作系统是centos7,在两个目录/var/www/example1和/var/www/example2有两个相同的文件student.txt,内容如下:

shool:No.1 School
class:class 3
grade:grade 2
name:test

我想把两个目录中的这个student.txt文件的第4行的test分别改成ZhangSan和LiSi,
我想写个shell脚本modify-name.sh来完成这个功能,可是不知道该怎么写,请大神帮写一下,谢谢!

素颜素颜2790 days ago1021

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 00:37:19

    How to batch modify file contents in Linux? -PHP Chinese website Q&A-How to batch modify file contents in Linux? -PHP Chinese website Q&A

    Let’s take a look and learn.

    reply
    0
  • 迷茫

    迷茫2017-03-02 09:54:44

    不必写脚本,用两条命令就可以解决了。如:

    sed -i '/name/s/test/ZhangSan/' /var/www/example1/student.txt
    sed -i '/name/s/test/LiSi/' /var/www/example2/student.txt


    reply
    0
  • Cancelreply