perl,sed replace, append sample

| | Comments (0)

在 ccc 後面加上一行 xxx

# cat test
aaa
bbb
ccc
ddd

# perl -pi -e "s/ccc/ccc\nxxx/" test

# cat test
aaa
bbb
ccc
xxx
ddd

把 xxx 換成 yyy
# perl -pi -e "s/xxx/yyy/" test

# cat test
aaa
bbb
ccc
yyy
ddd

把檔案中含有 xxx 字串的下一行加上一行 new line
# cat test
aaa 111
bbb 222
ccc 333
555 xxx 444
ddd kkkkkkkkkkkkk
xxx 666
mmmmmmmmmmmmm
lllllllllllllllllxxx
eeeeeee

# sed -e '/xxx/a\
new line' test > test.tmp

# mv test.tmp test

# cat test
aaa 111
bbb 222
ccc 333
555 xxx 444
new line
ddd kkkkkkkkkkkkk
xxx 666
new line
mmmmmmmmmmmmm
lllllllllllllllllxxx
new line
eeeeeee

Leave a comment

March 2009

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

About this Entry

This page contains a single entry by Pank published on November 14, 2003 9:06 AM.

postfix clean mail queue was the previous entry in this blog.

bin2iso for unix (website) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.