文件开头和末尾添加字符

[root@dbrg-2 test]# cat shuzi
xxx-12:2.4.6-2009.txt
yyy-1:3.1.-2009.txt
qq-34:4.5-299.txt

[root@dbrg-2 test]# sed s'/^/haha &/' shuzi
haha xxx-12:2.4.6-2009.txt
haha yyy-1:3.1.-2009.txt
haha qq-34:4.5-299.txt

[root@dbrg-2 test]# sed s'/$/ haha &/' shuzi
xxx-12:2.4.6-2009.txt haha
yyy-1:3.1.-2009.txt haha
qq-34:4.5-299.txt haha

[root@dbrg-2 test]# sed s'/$/& haha/' shuzi
xxx-12:2.4.6-2009.txt haha
yyy-1:3.1.-2009.txt haha
qq-34:4.5-299.txt haha
[root@dbrg-2 test]#

[root@dbrg-2 test]# vi shuzi

xxx-12:2.4.6-2009.txt
yyy-1:3.1.-2009.txt
qq-34:4.5-299.txt





~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"shuzi" 8L, 65C 已写入                                                                                                                    
[root@dbrg-2 test]# sed s'/$/haha &/' shuzi
xxx-12:2.4.6-2009.txthaha
yyy-1:3.1.-2009.txthaha
qq-34:4.5-299.txthaha
haha
haha
haha
haha
haha
[root@dbrg-2 test]# sed '/^[[:blank:]]*$/!s/$/haha &/' shuzi
xxx-12:2.4.6-2009.txthaha
yyy-1:3.1.-2009.txthaha
qq-34:4.5-299.txthaha





[root@dbrg-2 test]# sed '/^[[:blank:]]*$/!s/$/ haha &/' shuzi
xxx-12:2.4.6-2009.txt haha
yyy-1:3.1.-2009.txt haha
qq-34:4.5-299.txt haha





[root@dbrg-2 test]# sed '/^[[:blank:]]*$/!s/$/& haha/' shuzi
xxx-12:2.4.6-2009.txt haha
yyy-1:3.1.-2009.txt haha
qq-34:4.5-299.txt haha



[root@dbrg-2 test]# sed '/^[[:blank:]]*$/!s/^/&haha /' shuzi
haha xxx-12:2.4.6-2009.txt
haha yyy-1:3.1.-2009.txt
haha qq-34:4.5-299.txt


你可能感兴趣的:(职场,sed,休闲)