Is there an Awk or Perl one-liner that can remove all rows that do not have complete data. I find myself frequently needing something like this. For example, I currently have a tab-delimited file that looks like this:
1 asdf 2
9 asdx 4
3 ddaf 6
5 4
2 awer 4
How can a line that does not have a value in field 2 be removed?
How could a line that does not have a value in one of ANY field be removed?
I was trying to do something like this:
awk -F"\t" '{if ($2 != ''){print $0}}' 1.txt > 2.txt
Thanks.
In awk, if you know that every row should have exactly 3 elements:
awk -F'\t+' 'NF == 3' INFILE > OUTFILE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With