shell - How to selectively grep? -


i have file that's structured follows:

particle 1 0.1   0.988 0.2   0.975 0.2   0.945 0.3   0.900 ... ... particle 2 0.1   0.988 0.2   0.965 0.2   0.945 0.2   0.935 0.3   0.900 ... 

how grep first occurrence of 0.2 under each particle? e.g want grep like

particle 1 0.2 0.975 particle 2 0.2 0.965 

thanks in advance!!

this awk one-liner help:

awk '/particle/{print;p=1}p&&/^0\.2/{print;p=0}' file 

add test:

kent$  cat f particle 1 0.1 0.988 0.2 0.975 0.2 0.945 0.3 0.900 ..... ..... particle 2 0.1 0.988 0.2 0.965 0.2 0.945 0.2 0.935 0.3 0.900  kent$  awk '/particle/{print;p=1}p&&/^0\.2/{print;p=0}' f particle 1 0.2 0.975 particle 2 0.2 0.965 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -