由於目前測試的BIOS有一個option 發生了改變,因此我們需要在之前寫好的腳本上進行修改,將舊的option 改為新的選項,因此在此處用到了批量修改文件中的內容;
1. perl 命令替換:
perl -i -e "s/old/new/g" the path of the file
下面,就將test1 text2,中的cat 都換成了dog,汪汪~~
[root@11 tmp]# touch test1.txt [root@11 tmp]# vim test1.txt [root@11 tmp]# cat test1.txt cat cat cat i like linux i like windows too i like watching TV I like chenqingling [root@11 tmp]# cp test1.txt text2.txt [root@11 tmp]# cp test1.txt text3.txt [root@11 tmp]# cp test1.txt text4.txt [root@11 tmp]# perl -p -i -e "s/cat/dog/g" test1.txt text2.txt [root@11 tmp]# cat test1.txt dog dog dog i like linux i like windows too i like watching TV I like chenqingling [root@11 tmp]# cat text2.txt dog dog dog i like linux i like windows too i like watching TV I like chenqingling [root@11 tmp]# cat text3.txt cat cat cat i like linux i like windows too i like watching TV I like chenqingling
2.運用sed 命令批量修改文件內容:
sed -i "s/old/new/g" the path of the files
修改text2,text3,中的linux ,修改為Unix
[root@11 tmp]# sed -i "s/linux/Unix/g" text2.txt text3.txt [root@11 tmp]# cat text2.txt dog dog dog i like Unix i like windows too i like watching TV I like chenqingling [root@11 tmp]# cat text3.txt cat cat cat i like Unix i like windows too i like watching TV I like chenqingling [root@11 tmp]# cat test1.txt dog dog dog i like linux i like windows too i like watching TV I like chenqingling
3.補充點:將old 全部換成 new
sed -i “s/old/new/g” `grep old -rl /path` #當前路徑表示:./
[root@110 lu]# sed -i "s/TV/xiaozhan/g" `grep TV -rl ./` #注意這里的`` 不是單引號!! [root@11 lu]# cat text2.txt dog dog dog i like Unix i like windows too i like watching xiaozhan I like chenqingling [root@11 lu]# cat text3.txt cat cat cat i like Unix i like windows too i like watching xiaozhan I like chenqingling [root@11 lu]# cat text4.txt cat cat cat i like linux i like windows too i like watching xiaozhan I like chenqingling