你所不知道的sed用法

作者:网络医生 发布于:2012-5-30 15:28 Wednesday 分类:shell

文件test.log内容如下:

[root@num123 test]# cat test.log
23435435
122352315
454366
9504895
fksjdfkfj
fsfeesjdfkfj
ettteesjdfkfj

把每行第一个字符替换成aa

[root@num123 test]# sed 's/^./aa/g' test.log
aa3435435
aa22352315
aa54366
aa504895
aaksjdfkfj
aasfeesjdfkfj
aattteesjdfkfj

把每行前两个符替换成aa

[root@num123 test]# sed 's/^../aa/g' test.log
aa435435
aa2352315
aa4366
aa04895
aasjdfkfj
aafeesjdfkfj
aatteesjdfkfj

在每行的前面加上aa

[root@num123 test]# sed 's/^/aa/g' test.log
aa23435435
aa122352315
aa454366
aa9504895
aafksjdfkfj
aafsfeesjdfkfj
aaettteesjdfkfj

把每行的最后一个字符替换成aa

[root@num123 test]# sed 's/.$/aa/g' test.log
2343543aa
12235231aa
45436aa
950489aa
fksjdfkfaa
fsfeesjdfkfaa
ettteesjdfkfaa

把每行最后两个字符替换成aa

[root@num123 test]# sed 's/..$/aa/g' test.log
234354aa
1223523aa
4543aa
95048aa
fksjdfkaa
fsfeesjdfkaa
ettteesjdfkaa

在每行最后加上aa

[root@num123 test]# sed 's/$/aa/g' test.log
23435435aa
122352315aa
454366aa
9504895aa
fksjdfkfjaa
fsfeesjdfkfjaa
ettteesjdfkfjaa

标签: shell sed sed用法

发表评论:

  • 0
  • 2
  • 5
  • 6
  • 4

Powered by emlog