bash - Print only parts that match regex -
echo "a b _c d _e f" | sed 's/[ ]*_[a-z]\+//g'
the result a b d f
.
now, how can turn around, , print _c _e
, while assuming nothing rest of line?
if question "how can print substrings match specific regular expression using sed
?" hard achieve (and not obvious solution).
grep
more helpful in case:
$> echo "a b _c d _e f" | grep -o -p "(\ *_[a-z]+)" _c _e
and finally
$> echo `echo "a b _c d _e f" | grep -o -p "(\ *_[a-z]+)"` _c _e
Comments
Post a Comment