我有这样的文本文件:
word1 & wordff 39 0: sgfdgggg, sgdgsd
word23 & sgfdgsdgsdgdg 44 0: sgdggfg, sfgdgdg
word45 *
我需要这个:
word1 &
word23 &
word45 *
如何在GREP中完成?
答案 0 :(得分:3)
grep -Eo '.*?[&*#]'
例如:
kent$ echo "word1 & wordff 39 0: sgfdgggg, sgdgsd
word23 & sgfdgsdgsdgdg 44 0: sgdggfg, sfgdgdg
word45 *"|grep -Eo '.*?[&*#]'
word1 &
word23 &
word45 *