我需要帮助“点击”从“TEST FILE”开始到“;”的行。我对任何其他方法如awk
持开放态度文件A包含以下内容:
TEST FILE ABC
this file contains ABC;
TEST FILE DEF
this file contains DEF
;
TEST FILE (DEF) this file contains (DEF);
TEST FILE DGHT this file contains DGHT;
TEST FILE 123
this file contains ABC,
this file contains DEF,
this file contains XYZ,
this file contains KLM
;
我想要以下5个文件
File1中
TEST FILE ABC
this file contains ABC;
文件2
TEST FILE DEF
this file contains DEF
;
文件3
TEST FILE (DEF) this file contains (DEF);
FILE4
TEST FILE DGHT this file contains DGHT;
File5
TEST FILE 123
this file contains ABC,
this file contains DEF,
this file contains XYZ,
this file contains KLM
;
答案 0 :(得分:0)
关注awk
可能对您有帮助。
awk '/TEST/{flag=1;++i} flag{print > "file"i} /;$/{flag=""}' Input_file
现在也添加非单线形式的解决方案。
awk '
/TEST/{
flag=1;
++i}
flag{
print > "file"i}
/;$/{
flag=""}
' Input_file