Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/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
Sed 删除bash中两个模式之间的部分_Sed - Fatal编程技术网

Sed 删除bash中两个模式之间的部分

Sed 删除bash中两个模式之间的部分,sed,Sed,比如说,我有一个巨大的文件: (Ano_gla|EOG091B00FI:0.21327484,Tri_cas|EOG091B00FI:0.14561670,((Tri_bro|EOG091B00FI:0.00523450,Tri_jap|EOG091B00FI:0.01261030)1.00 0000:0.26780267,(((((Orm_nit|EOG091B00FI:0.00243200,Orm_pom|EOG091B00FI:0.00914980)1.000000:0.08747204,

比如说,我有一个巨大的文件:

(Ano_gla|EOG091B00FI:0.21327484,Tri_cas|EOG091B00FI:0.14561670,((Tri_bro|EOG091B00FI:0.00523450,Tri_jap|EOG091B00FI:0.01261030)1.00
0000:0.26780267,(((((Orm_nit|EOG091B00FI:0.00243200,Orm_pom|EOG091B00FI:0.00914980)1.000000:0.08747204,(((((Meg_dor|EOG091B00FI:0.0
0953580,Meg_sti|EOG091B00FI:0.02205870)1.000000:0.09005934,(Cer_mar|EOG091B00FI:0.00429740,Cer_sol|EOG091B00FI:0.02112877)1.000000:
0.07852307)0.937000:0.01510878,(((Cec_fun|EOG091B00FI:0.04067119,(Tri_sar|EOG091B00FI:0.00462004,(Nas_gir|EOG091B00FI:0.00126111,Na
s_lon|EOG091B00FI:0.00087461)0.877000:0.00251191)0.995000:0.01752929)1.000000:0.04366313,(Tri_bra|EOG091B00FI:0.00461186,Tri_pre|EO
G091B00FI:0.01023626)1.000000:0.44067486)0.000000:0.01008020,(Ana_pse|EOG091B00FI:0.07264534))
我正在寻找一种bash方法,以便删除|和之间的部分:

并获得:

(Ano_gla:0.21327484,Tri_cas:0.14561670,((Tri_bro:0.00523450,Tri_jap:0.01261030)1.00
0000:0.26780267,(((((Orm_nit:0.00243200,Orm_pom:0.00914980)1.000000:0.08747204,(((((Meg_dor:0.0
0953580,Meg_sti:0.02205870)1.000000:0.09005934,(Cer_mar:0.00429740,Cer_sol:0.02112877)1.000000:
0.07852307)0.937000:0.01510878,(((Cec_fun:0.04067119,(Tri_sar:0.00462004,(Nas_gir:0.00126111,Na
s_lon:0.00087461)0.877000:0.00251191)0.995000:0.01752929)1.000000:0.04366313,(Tri_bra:0.00461186,Tri_pre:0.01023626)1.000000:0.44067486)0.000000:0.01008020,(Ana_pse:0.07264534
我试过:

sed -e 's/\(|\).*\(:\)/\1\2/g' myfile 
但它不起作用

$ sed 's/|[^|:]*:/:/g' file
(Ano_gla:0.21327484,Tri_cas:0.14561670,((Tri_bro:0.00523450,Tri_jap:0.01261030)1.00
0000:0.26780267,(((((Orm_nit:0.00243200,Orm_pom:0.00914980)1.000000:0.08747204,(((((Meg_dor:0.0
0953580,Meg_sti:0.02205870)1.000000:0.09005934,(Cer_mar:0.00429740,Cer_sol:0.02112877)1.000000:
0.07852307)0.937000:0.01510878,(((Cec_fun:0.04067119,(Tri_sar:0.00462004,(Nas_gir:0.00126111,Na
s_lon:0.00087461)0.877000:0.00251191)0.995000:0.01752929)1.000000:0.04366313,(Tri_bra:0.00461186,Tri_pre|EO
G091B00FI:0.01023626)1.000000:0.44067486)0.000000:0.01008020,(Ana_pse:0.07264534))
或者,如果您的输入确实跨行中断,那么使用GNU sed for-z:

sed':a;$!{N;ba};s/|[^:://g'我的文件 解释:

:要跳转到的标签 $! {除了最后一行之外,每行都有 N将下一行追加到模式空间 ba跳转到标签 } s/|[^::://g移除所有管道,直到并排除下一个冒号 这会将整个文件拖入模式空间,然后进行一次全局替换

请注意,这将保留输入文件的关闭位置,与预期的输出不同

对于GNU sed以外的sed,命令必须稍微分开,以便标签分开:

sed-e':a'-e'$!{N;ba;}'-e's/|[^:://g'myfile
如果您的数据在“d”文件中,请尝试gnu sed

sed -E 's/\|[^:]+:/:/g' d

为什么要捕获|如果你想让它消失?文件末尾的发生了什么?输入文件真的包含多行吗?如果是的话,输出中的行数是否重要?a | b | c:d应该变成a:d还是a | b:d或其他东西?如何工作?你找不到替补吗?或者它替换了太多?预期的输出表明有一个事件跨越换行符输出只有5行。
sed -E 's/\|[^:]+:/:/g' d