- 论坛徽章:
- 780
|
本帖最后由 Herowinter 于 2014-09-04 13:22 编辑
回复 35# xiao_244
这个文本,我这边这段代码执行没问题的,前面算变量m的sed代码应该
有些特性在你的系统里不支持,导致m为空,然后s命令就会有问题。
- [root@lnx-rh6-x64 zzz]# m=`sed -nr '0,/0x0000000a/{//s/.*= "(([0-9A-Fa-f]{2}:){3}).*/\1/p}' mac.txt`;echo $m
- D8:49:0B:
- [root@lnx-rh6-x64 zzz]# sed "s//22/" mac.txt
- sed: -e expression #1, char 0: no previous regular expression
- [root@lnx-rh6-x64 zzz]#
复制代码 改成这样严谨一点,但你的系统估计还是不行,也许不支持//- m=`sed -nr '0,/0x0000000a/{//s/.*= "(([0-9A-Fa-f]{2}:){3}).*/\1/p}' mac.txt`;[ -n "$m" ]&&sed "s/$m/22:33:44:/" mac.txt
- obj.id = "0x00000007" ; obj.value = "021VQR3GE2161594";
- obj.id = "0x00000008" ; obj.value = "631458q5e2";
- obj.id = "0x00000009" ; obj.value = "";
- obj.id = "0x0000000a" ; obj.value = "22:33:44:3D:74:2D";
- obj.id = "0x0000000b" ; obj.value = "65:D9:80:13:00:0B";
- obj.id = "0x00000022" ; obj.value = "";
- obj.id = "0x00000023" ; obj.value = "";
- obj.id = "0x00000024" ; obj.value = "";
- obj.id = "0x0000000c" ; obj.value = "22:33:44:3D:74:2E";
- obj.id = "0x0000000d" ; obj.value = "22:33:44:3D:74:2F";
- obj.id = "0x0000000e" ; obj.value = "22:33:44:3D:74:30";
- obj.id = "0x00000013" ; obj.value = "22:33:44:3D:74:35";
- obj.id = "0x00000016" ; obj.value = "738011635059";
复制代码 可以试一下这段代码,我去掉了//,也许可以。
- m=`sed -nr '/0x0000000a/{s/.*= "(([0-9A-Fa-f]{2}:){3}).*/\1/p;q}' mac.txt`;[ -n "$m" ]&&sed "s/$m/22:33:44:/" mac.txt
- obj.id = "0x00000007" ; obj.value = "021VQR3GE2161594";
- obj.id = "0x00000008" ; obj.value = "631458q5e2";
- obj.id = "0x00000009" ; obj.value = "";
- obj.id = "0x0000000a" ; obj.value = "22:33:44:3D:74:2D";
- obj.id = "0x0000000b" ; obj.value = "65:D9:80:13:00:0B";
- obj.id = "0x00000022" ; obj.value = "";
- obj.id = "0x00000023" ; obj.value = "";
- obj.id = "0x00000024" ; obj.value = "";
- obj.id = "0x0000000c" ; obj.value = "22:33:44:3D:74:2E";
- obj.id = "0x0000000d" ; obj.value = "22:33:44:3D:74:2F";
- obj.id = "0x0000000e" ; obj.value = "22:33:44:3D:74:30";
- obj.id = "0x00000013" ; obj.value = "22:33:44:3D:74:35";
- obj.id = "0x00000016" ; obj.value = "738011635059";
复制代码 |
|