[英]how to extract particular string with special character from each line of a file
I have a file with a jungle of strings. 我有一个带有字符串丛林的文件。 Few lines read as follows:
几行内容如下:
2*H[0, 3, y]*Log[1 - z] - 2*H[2, 3, y]*Log[1 - z] +
6*H[2, 2, 0, y] + 6*H[2, 2, 2, y] - 48*Log[-Q2] + 12*zeta2*Log[-Q2] +
(-107 + 12*N^2*(-1 + N^2))*z^2))*(H[0, 1, 0, y] + H[0, 1, 0, z] + ...
I want to find different unique combination of 我想找到不同的独特组合
H[*,*,*] or H[*,*,*,*]
coming in each line. 进入每一行。 Therefore I have to search for string containing special characters too.
因此,我也必须搜索包含特殊字符的字符串。 Is there any way to do in shell?
有什么办法可以做壳吗?
You can use this gnu awk command with custom RS
: 您可以将此gnu awk命令与自定义
RS
:
awk -v RS='H\\[[^]]*\\]' 'RT && !seen[RT]++{print RT}' file
H[0, 3, y]
H[2, 3, y]
H[2, 2, 0, y]
H[2, 2, 2, y]
H[0, 1, 0, y]
H[0, 1, 0, z]
Regex H\\\\[[^]]*\\\\]
will set each instance of H[...]
as record separator. 正则表达式
H\\\\[[^]]*\\\\]
将H[...]
每个实例设置为记录分隔符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.