Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 扫描文件的每一行并查找匹配项(|###|),如果找到,请在下一行前面添加双引号_Shell_Unix - Fatal编程技术网

Shell 扫描文件的每一行并查找匹配项(|###|),如果找到,请在下一行前面添加双引号

Shell 扫描文件的每一行并查找匹配项(|###|),如果找到,请在下一行前面添加双引号,shell,unix,Shell,Unix,以下要求需要您的帮助和建议 阅读每一行并查找“|##|”(这是我的结束行字符)如果找到,请在下一行的前面或开头插入/添加双引号(“) 输入文件#1: 预期产出: 101|*|101-C-01071|*|FIRSTLINE|##| "102|*|DOUBT and Stage go to and admin|*|SIMCA-ON|##| "103|*|101-C-01071|*|VEEVA|##| 输入文件#2: 结果: 101|*|101-C-01071|*|Integrity Testin

以下要求需要您的帮助和建议

阅读每一行并查找“|##|”(这是我的结束行字符)如果找到,请在下一行的前面或开头插入/添加双引号(“)

输入文件#1:

预期产出:

101|*|101-C-01071|*|FIRSTLINE|##|
"102|*|DOUBT and Stage go to 
and admin|*|SIMCA-ON|##|
"103|*|101-C-01071|*|VEEVA|##|
输入文件#2:

结果:

101|*|101-C-01071|*|Integrity Testing of Bleed Back Filter (Emflon II ) Installed on ETC Autoclave|*|PUBLIC|*||*|Y|*|Y|*||*|CFC6E8227CDB0A7AE040800AA5644B19|*|mdarling|*|2007.06.22 09:59:03|##|
"102|*|102-CC-10|*|Sterilization and Leak Rate Testing of Stokes Style Freeze Drier|*|PUBLIC|*||*|Y|*|Y|*||*|CFC6E8227CDC0A7AE040800AA5644B19|*|mdarling|*|2007.06.22 10:00:05|##|
103|*|103-CC-13|*|CIP/SIP Leak Testing Hull 380sq. ft. Freeze Drier|*|PUBLIC|*||*|Y|*|Y|*||*|CFC6E8227CDD0A7AE040800AA5644B19|*|mdarling|*|2007.06.22 10:00:16|##|
"104|*|104-CC-15|*|Emergency Situations & Alarms Involving the Automated Hull Freeze Drier Control|*|PUBLIC|*||*|Y|*|Y|*||*|CFC6E8227CDE0A7AE040800AA5644B19|*|mdarling|*|2007.06.22 10:00:32|##|
Sed工程:

sed -n ':a;/|##|/{p;n;s/^/"/;ba;};p;'

现场示例可从以下网址获得。

awk解决方案如何:

> cat in_file
101|*|101-C-01071|*|FIRSTLINE|##|
102|*|DOUBT and Stage go to
and admin|*|SIMCA-ON|##|
103|*|101-C-01071|*|VEEVA|##|
> awk -F" " ' { if($0~/\|##\|/) { print; getline; print "\x22"$0 } else { print } } ' in_file
101|*|101-C-01071|*|FIRSTLINE|##|
"102|*|DOUBT and Stage go to
and admin|*|SIMCA-ON|##|
"103|*|101-C-01071|*|VEEVA|##|
>
EDIT1:

> cat double_quote.txt
101||101-C-01071||Integrity Testing of Bleed Back Filter (Emflon II ) Installed on ETC
Autoclave||PUBLIC||||Y||Y||||CFC6E8227CDB0A7AE040800AA5644B19||mdarling||2007.06.22
09:59:03|##| 102||102-CC-10||Sterilization and Leak Rate Testing of Stokes Style Freeze
Drier||PUBLIC||||Y||Y||||CFC6E8227CDC0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:05|##| 103||103-CC-13||CIP/SIP Leak Testing Hull 380sq. ft. Freeze
Drier||PUBLIC||||Y||Y||||CFC6E8227CDD0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:16|##| 104||104-CC-15||Emergency Situations & Alarms Involving the Automated Hull Freeze
Drier Control||PUBLIC||||Y||Y||||CFC6E8227CDE0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:32|##| strong text
>
>  awk -F" " ' { if($0~/\|##\|/) { print; pre=$0;getline; if(pre!=$0) {print "\x22"$0 } } else { print } } '  double_quote.txt
101||101-C-01071||Integrity Testing of Bleed Back Filter (Emflon II ) Installed on ETC
Autoclave||PUBLIC||||Y||Y||||CFC6E8227CDB0A7AE040800AA5644B19||mdarling||2007.06.22
09:59:03|##| 102||102-CC-10||Sterilization and Leak Rate Testing of Stokes Style Freeze
"Drier||PUBLIC||||Y||Y||||CFC6E8227CDC0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:05|##| 103||103-CC-13||CIP/SIP Leak Testing Hull 380sq. ft. Freeze
"Drier||PUBLIC||||Y||Y||||CFC6E8227CDD0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:16|##| 104||104-CC-15||Emergency Situations & Alarms Involving the Automated Hull Freeze
"Drier Control||PUBLIC||||Y||Y||||CFC6E8227CDE0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:32|##| strong text
>

您好,谢谢您的快速回复。请以:x2的身份登录[x2inform@nahas05190~]$cd/informat/Projects/LOS/\u首字母[x2inform@nahas05190(u首字母)]$sed-n:a;/| | | |$/{p;n;s/^/“/”ba;};p、 "用上面的sed命令试过了,但它不起作用,我有什么错误吗…下面的附加屏幕截图我不知道你附加了什么(在评论中),检查行尾,通过dos2unix运行它。对不起,我不能附加屏幕截图上面的命令在unix bash中不起作用?-我用putty测试谢谢你,先生,它起作用了。。将测试原始文件,并在有任何帮助时通知您。是。。请考虑接受答案和投票。您好,先生,当我尝试下一个测试时,它跳过在双线引号中添加双引号101×10*C-01071**完整性测试(EfFRON II)。目前,你们们的现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场的灭菌和泄漏率测试。现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场测试。现场现场现场现场现场现场现场现场现场现场| |*| CFC6E8227CDC0A7AE040800AA5644B19 |*| mdarling |*| 2007.06.22 10:00:05 | | |#| |您也可以在文件103 |*| 103-CC-13 |*| CIP/SIP泄漏测试船体380sq。该国目前的硬质合金??124四四四四个州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州各州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州州CFC6E8227CDE0A7AE040800AA5644B19 | | | | | mdarling | | | | 2007.06.22 10:00:32 | | | | |#| | | | | | | |一行打印。。请你在问题本身中更新一下好吗。。你必须缩进4个空格
> cat in_file
101|*|101-C-01071|*|FIRSTLINE|##|
102|*|DOUBT and Stage go to
and admin|*|SIMCA-ON|##|
103|*|101-C-01071|*|VEEVA|##|
> awk -F" " ' { if($0~/\|##\|/) { print; getline; print "\x22"$0 } else { print } } ' in_file
101|*|101-C-01071|*|FIRSTLINE|##|
"102|*|DOUBT and Stage go to
and admin|*|SIMCA-ON|##|
"103|*|101-C-01071|*|VEEVA|##|
>
> cat double_quote.txt
101||101-C-01071||Integrity Testing of Bleed Back Filter (Emflon II ) Installed on ETC
Autoclave||PUBLIC||||Y||Y||||CFC6E8227CDB0A7AE040800AA5644B19||mdarling||2007.06.22
09:59:03|##| 102||102-CC-10||Sterilization and Leak Rate Testing of Stokes Style Freeze
Drier||PUBLIC||||Y||Y||||CFC6E8227CDC0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:05|##| 103||103-CC-13||CIP/SIP Leak Testing Hull 380sq. ft. Freeze
Drier||PUBLIC||||Y||Y||||CFC6E8227CDD0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:16|##| 104||104-CC-15||Emergency Situations & Alarms Involving the Automated Hull Freeze
Drier Control||PUBLIC||||Y||Y||||CFC6E8227CDE0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:32|##| strong text
>
>  awk -F" " ' { if($0~/\|##\|/) { print; pre=$0;getline; if(pre!=$0) {print "\x22"$0 } } else { print } } '  double_quote.txt
101||101-C-01071||Integrity Testing of Bleed Back Filter (Emflon II ) Installed on ETC
Autoclave||PUBLIC||||Y||Y||||CFC6E8227CDB0A7AE040800AA5644B19||mdarling||2007.06.22
09:59:03|##| 102||102-CC-10||Sterilization and Leak Rate Testing of Stokes Style Freeze
"Drier||PUBLIC||||Y||Y||||CFC6E8227CDC0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:05|##| 103||103-CC-13||CIP/SIP Leak Testing Hull 380sq. ft. Freeze
"Drier||PUBLIC||||Y||Y||||CFC6E8227CDD0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:16|##| 104||104-CC-15||Emergency Situations & Alarms Involving the Automated Hull Freeze
"Drier Control||PUBLIC||||Y||Y||||CFC6E8227CDE0A7AE040800AA5644B19||mdarling||2007.06.22
10:00:32|##| strong text
>