extract specific line from a file using awk -
the data in file:
... ... b c d letters f g h letters j k letters ... ...
using,
awk '/letters/' file
the result is:
a b c d letters f g h letters j k letters
however want have following result (without tab , 'letters' word , single line better):
a b c d e f g h j k
how can achieve this?
quick , dirty:
awk '$nf=="letters"{sub($nf,"");s=s $0}end{sub(/ *$/,"",s);print s}' file
with example:
kent$ echo "... ... b c d letters f g h letters j k letters ... ..."|awk '$nf=="letters"{sub($nf,"");s=s $0}end{sub(/ *$/,"",s);print s}' b c d f g h j k
so output in oneline, without trailing spaces.
Comments
Post a Comment