分类:
2006-02-21 21:18:52
CODE:解决方法:
$ cat hebing.txt
This is a test,
abcde
hello
ok
abcde
the botto
abcde
m.
This is a test,
abcde
hello
ok
abcde
the botto
abcde
m.
CODE:2.awk实现
$ sed -e '/abcde/{N;s/\n/ /}' hebing.txt
This is a test,
abcde hello
ok
abcde the botto
abcde m.
This is a test,
abcde hello
ok
abcde the botto
abcde m.
CODE:注意:上面用awk实现的使用的是printf不是print。
$ awk '{if(/abcde/){printf $0" ";next} else{print}}' hebing.txt
This is a test,
abcde hello
ok
abcde the botto
abcde m.
This is a test,
abcde hello
ok
abcde the botto
abcde m.
CODE:要求对所有的日期都匹配,然后日期所在的位置是不定的
0516001|uuu|0|0|0|1|1899/12/31|1899/12/31|2005/03/18|180|
0516001|uuu|0|0|0|1|1899/12/31|1899/12/31|2004/03/24|180|
0516001|uuu|0|1|0|0|2004/02/09|1899/12/31|1899/12/31|0|
CODE:解释:\n与模式中第n(单个数字)个 /(\) 指定的子字符串匹配,正则表达式在/(和\)之间的。
$ sed 's/\([0-9]\{4\}\)\/\([0-9]\{2\}\)\/\([0-9]\{2\}\)/\3\/\2\/\1/g' date.txt
0516001|uuu|0|0|0|1|31/12/1899|31/12/1899|18/03/2005|180|
0516001|uuu|0|0|0|1|31/12/1899|31/12/1899|24/03/2004|180|
0516001|uuu|0|1|0|0|09/02/2004|31/12/1899|31/12/1899|0|
CODE:注意:[]要转义的。如果不转义的话。
$ cat kuohao
{]
[] hsadfk
[ ] jsadfj
hfndh[]
$ sed '/\[ \]/d' kuohao
{]
[] hsadfk
hfndh[]
$ grep -v '\[ \]' kuohao
{]
[] hsadfk
hfndh[]
CODE:四.
$ sed '/[ ]/d' kuohao
{]
hfndh[]
CODE:输入modules/ppp 输出ppp.so
sed 's/modules\/\([^/ ]*\)\/*/\1.so/g'