今天更新区组列表文件,其中F=16的状态是隐藏的状态,玩家是看不到的,其他F=0,添加维护中是需要将S=0变为S=10,F=0,而同步后登录游戏发现区组列表中隐藏的测试区组也出现了并且是维护的状态!
查看脚本,发现用sed将所有的F全部=0了,没有考虑隐藏F=16的情况。
<Server N="测试" A="xx.xx.xx.xx" P="12345" S="0" F="16" />
sed -i -r "s/ S=\"[[:digit:]]*\" / S=\"10\" /g" $1
心想:sed有没有像if/else的语法呢,上网查询发现有个用法叫"标签/lable"
QUOTE: b label Branch to label; if label is omitted, branch to end of script. t label If a s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script. T label If no s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script. b、t和T的共同点是“if label is omitted, branch to end of script”不同点是b无条件跳转,t和T有条件跳转
[[email protected] ~]# sed ‘{ /label/b there; \\当匹配label时,就跳转到比标签there那,然后执行下面的s/$/ \!/语句,而s/label/LABEL/;语句就不执行了。 s/label/LABEL/; :there; \\ 定义一个标签there。 s/$/ \!/}‘ test This is a label A ! This is a label B ! This is a label C ! This is a label D !
请看如下代码:
[[email protected]A ~]# cat c aaa bbb ccc ddd eee fff [[email protected] ~]# sed ‘/ccc/s/$/\tYES/;ta;s/$/\tNO/;:a‘ c aaa NO bbb NO ccc YES ddd NO eee NO fff NO
sed的标签用法
时间: 2024-10-27 09:08:04