我有几个文件格式如下
some text
some text
This section is for WXYZ
some text
some text
some text
some text
some text
some text (ABC) some text (CDF)
901 98
some text FFG
some text (FFG)
1 99
some text
some text
我正在尝试打印每个文件
- 文件名
- 同一行中“This section is for”后面的字符串
- 包含以下字符串的行
(ABC)
- 包含以下字符串的行
(FFG)
这是我当前的脚本(基于此线程中的答案)
awk '/This section is for/{sub(/This section is for /,""); print FILENAME "|" $0}
a{print;a=0} /\(ABC\)/{a=1}
b{print;b=0} /\(FFG\)/{b=1}
' "testfile.txt"
我得到了这个输出
testfile.txt|WXYZ
901 98
1 99
我希望每个文件的输出都是一行,像这样
testfile.txt|WXYZ|901 98|1 99
如何修改脚本以实现我的目标?谢谢