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来完成这个功能,可是不知道该怎么写,请大神帮写一下,谢谢!
数据分析师2017-10-01 00:37:19
Linux에서 파일 내용을 일괄 수정하는 방법은 무엇입니까? -PHP 중국어 사이트 Q&A -리눅스에서 파일 내용을 일괄 수정하는 방법은 무엇인가요? -PHP 중국어 홈페이지 Q&A
꼭 보고 배워보세요.
迷茫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