2011-03-01 58 views
0

我只是没有得到我的头在模式匹配在sed,更糟糕的是,有报价作为分隔符。使用集提取匹配的模式使用'作为模式分隔符

我做的:

cat file | grep \'*.s\' 

,并得到:

'PhaseRayA:  '  'sca/sca_out/sc_ray_a.s' 
'PhaseRayO:  '  'sca/sca_out/sc_ray_o.s' 

作为输出。一个现在我想提取:

sca/sca_out/sc_ray_a 
sca/sca_out/sc_ray_o.s.s 

所以我的模式是“* .S”,用引号是模式的一部分,但不是想要的结果的一部分。

有关于此的任何想法?我猜sed会干这份工作,但不知道如何... 感谢您的帮助... 一切顺利,André

回答

0

您的问题有点含糊不清,但这应该做我认为你的意思:

sed -e "s/'[^']*' *'//" -e "s/'//" file 
0

你可能要考虑AWK:

$ cat test.txt 
'PhaseRayA:  '  'sca/sca_out/sc_ray_a.s' 
'PhaseRayO:  '  'sca/sca_out/sc_ray_o.s' 

$ awk -F "'" '{print $4}' test.txt 
sca/sca_out/sc_ray_a.s 
sca/sca_out/sc_ray_o.s 

我倾向于使用sed来编辑文件和awk来处理它们。 awk是为打破记录而建立的。

0

这给一试:

sed "s/.*'\([^']*\)'/\1/" inputfile 

同理:

sed 's/.*\o47\([^\o47]*\)\o47/\1/' inputfile # that's the letter "o" between the backslash and the 4 

sed 's/.*\x27\([^\x27]*\)\x27/\1/' inputfile