- 论坛徽章:
- 0
|
sed 当前结果的下一行,怎么标识
测试
将匹配范围后的所有文本加上 ' ->',这只是一个例子,具体要作如何处理你可以自己改一下。
shell script
- #!/bin/sh
- if [ -z $1 ];then echo lost param.;exit 1;fi
- cat 1.txt |\
- awk "/$1/,/EndLine/{\
- print;\
- if(/EndLine/){sem=1;next}\
- };\
- sem==1{printf(\"-> %s\n\",\$0)}"
复制代码
1.txt文件内容
- $ cat 1.txt
- hello
- EndLine
- windows
- done
- EndLine
- world
- can
- doit
- EndLine
- This line will continue
- EndLine
- 002 40 400
- done
- $
- $ ./test.sh world
- world
- can
- doit
- EndLine
- -> This line will continue
- -> EndLine
- -> 002 40 400
- -> done
- $ ./test.sh windows
- windows
- done
- EndLine
- -> world
- -> can
- -> doit
- -> EndLine
- -> This line will continue
- -> EndLine
- -> 002 40 400
- -> done
- $
复制代码 |
|