I am working on mac with sed, perl, awk, bash..
I have a large-ish (10GB) text file which has 13 fields (columns) of TAB
delimited data. Unfortunately some of these lines have extraneous TABs
, so I want to delete the entire line where we have extra TABs
, and thus unequal fields. (I don't mind discarding the lines in their entirety)
What I currently have writes the number of fields into another file.
awk -F'\t' '{print NF}' infile > fieldCount
head fieldCount
13
13
10
13
13
13
14
13
13
13
I would like to construct a short script that removes any line with more (or less) than 13 proper fields (from the original file).
- speed is helpful as I have to do this on multiple files
- doing it in one sweep would be cool
- I currently am porting the fieldCount file into Python, trying to load with line by line.
EDIT:
vaild (13 columns)
a b c d e f g h i j k l m
invalid (14 columns)
a b c d e f g h i j k l m n