Hi,
I would like to know how can I delete rows of a text file if from the 3rd column onwards there is only zeros?
Thanks in advance
Hi,
I would like to know how can I delete rows of a text file if from the 3rd column onwards there is only zeros?
Thanks in advance
Please provide an input sample and desired output and what you have tried so far..
Thanks for the reply.
Example Input file:
a b 0 0 0 0 0
a d 0 1 0 0 1.5
d r 0 0 0 0 0
Desired output file:
a d 0 1 0 0 1.5
Perhaps:
egrep -v "^[^ ]+ +[^ ]+( +0)*$" filename > outfile
another way
awk '{x=0;for(i=3;i<=NF;i++)x+=$i}x>0' infile
awk '$3||$4||$5||$6||$7' infile
awk '{for(i=3;i<=NF;i++)if($i>0){print;next}}' input.txt
Thanks a lot to everyone!
I am also interested in getting a similar output but now only output the lines where the number of zeros in each row (starting from column 3) is equal or less than 5% of the total numbers per line (also starting only at column 3).
Thanks in advance