sed -i '$a service snmpd start' /etc/rc.local
sed -i "41s:public:mykey:g" /etc/snmp/snmpd.conf
sed -i "85s:#::g" /etc/snmp/snmpd.conf
参考资料:
http://www.oschina.net/question/179732_114320
昨天在linux下的某個文件插入另外一個文件的內容
發現原來awk也可以同樣處理,我承認我不是很熟shell
代碼如下:
1
2
3
4
5
6
7
8
9
|
#如果知道行号可以用下面的方法 sed -i '88 r b.file' a. file #在a.txt的第88行插入文件b.txt awk '1;NR==88{system("cat b.file")}' a. file > a. file #如果不知道行号,可以用正則匹配 sed -i '/regex/ r b.txt' a.txt # regex是正则表达式 awk '/target/{system("cat b.file")}' a. file > c. file #sed的話如果不改变源文件,可以去掉-i开关,修改会输出到STDOUT |
---------------话题补充---------------
@_K_:希望可以幫到有用的人 (1年前)