LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 960|回复: 6

如何用sed实现这个?

[复制链接]
发表于 2003-9-4 20:19:50 | 显示全部楼层 |阅读模式
file:
there is - 3 test data file -- you and me
there is - 4 test data file -- you and me
there is - 5 test data file -- you and me

希望能够用一句sed把它变成
there is -03 test data file -- you and me
there is -04 test data file -- you and me
there is -05 test data file -- you and me


其实就是将- X变成-0X
谢谢!
发表于 2003-9-5 09:25:26 | 显示全部楼层
$ cat a
there is - 3 test data file -- you and me
there is - 4 test data file -- you and me
there is - 5 test data file -- you and me
$ cat a | sed 's/ - \([0-9]*\) / -0\1 /'
there is -03 test data file -- you and me
there is -04 test data file -- you and me
there is -05 test data file -- you and me
 楼主| 发表于 2003-9-5 10:03:13 | 显示全部楼层
idkey:
非常感谢!
发表于 2003-9-11 01:44:47 | 显示全部楼层
use awk ;)
[/home/javalee/myshell]cat a
there is - 3 test data file -- you and me
there is - 4 test data file -- you and me
there is - 5 test data file -- you and me
[/home/javalee/myshell]cat a|tr -d -|awk '$3="-0"$3{print}'|awk '$7="-- "$7{print}'
there is -03 test data file -- you and me
there is -04 test data file -- you and me
there is -05 test data file -- you and me
发表于 2003-9-11 09:13:58 | 显示全部楼层
最初由 javalee 发表
use awk ;)
[/home/javalee/myshell]cat a
there is - 3 test data file -- you and me
there is - 4 test data file -- you and me
there is - 5 test data file -- you and me
[/home/javalee/myshell]cat a|tr -d -|awk '$3="-0"$3{print}'|awk '$7="-- "$7{print}'
there is -03 test data file -- you and me
there is -04 test data file -- you and me
there is -05 test data file -- you and me

呵呵,看起来有点大炮打蚊子的感觉。
发表于 2003-9-13 12:53:57 | 显示全部楼层
我是 新手也来凑个热闹,呵呵:
略有不同

sed 's/-\([0-9]\)/-0\1/' filename
 楼主| 发表于 2003-9-13 22:56:38 | 显示全部楼层
呵呵,多谢各位支持!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表