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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -