I have several hundred text files consisting each of five tab delimited columns. The first column contains an index and the following four the count of occurrences. Now I would like to count the number of rows that contain 3 columns with 0 (i.e. 7 rows in the example below).
1 0 0 0 9
2 0 9 0 0
3 10 0 0 0
4 0 10 4 0
5 0 0 0 10
6 0 0 0 10
7 0 0 0 10
8 0 10 0 0
9 5 0 5 0
I can code this as a loop in R, but as the original files each contain 60+ million rows, I wonder if there is no workaround with awk or sed and wc -l.
n
solution. limiting the answer to precisely 3 zeros and assuming the first one is never zero doesn't look like a general (forn
) solution. – Dec 20 '19 at 20:51abc 0 0 3 4
or++2 0 0 2 3
or0x3 0 2 0 7
or!4 0 0 3 5
and then try:perl -ale 'print if (grep{$_ == 0 } @F) == 3' file
. You will see the effect. – Dec 20 '19 at 20:51