Print lines that match certain criteria

Hi all

I have a text file with the following format:
id col1 col2 col3 col4 col5 col6 col7 ...

row1 0 0 0 0 0 0 0
row2 0 0 0 0 0 0 0
row3 0 0 0 0 0 0.2 0
row4 0 0 0 0 0 0 0
row5 0 0 0 0 0 0 0
row6 0 0 0 0.1 0 0 0
row7 0 0 0 0 0 0 0
row8 0 0 0 0 0 0 0
row9 0 0 0 0 0 0 0
...

The file is though much larger than this around 3000 rows and 5000 columns. Most lines have only zeros but values are in range of [0,1]. I am interested to print out all lines were there are some values > 0.

I created a short awk script like this:

awk 'BEGIN { OFS="" ; ORS="" } ; { for ( i=2; i<NF; i++ ) if($i > 0) print $i " "; print $NF "\n" }' 

But that one printed only the values that were greater than zero (and also a little bit more) and I need to print the whole line.

I would really appreciate any help and I hope that my query is clear enough:).

-Gauti

Try:

awk '{for (i=2;i<NF;i++) if($i>0){print;next}}' file
1 Like

Thank you bartus11 for a very quick answer, your code worked perfectly.