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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -