gsub和awk从字符串“abc_xyz_def_aaa”和abc_def_zyz“

时间:2017-02-24 09:20:17

标签: regex

我的字符串就像

abc_def_xyz and 
abc-def_ghj_fff

我想从字符串

中仅提取xyz and ghj_fff

2 个答案:

答案 0 :(得分:0)

你可以找到

([^_\s]+_){2}

并替换为空白字符串

答案 1 :(得分:0)

这是您要找的输出吗?

awk -F 'def_' '{print $2}' file
xyz and 
ghj_fff