can anyone help
i have a file containing tab separated values, there should be 26 tabs per record but some have more i want to copy out of the file those record that do have 26 per line so i can ingest the file
something like
cat infile |grep "/t"*<26 times> >outfile
thanks
Matt
it may be possible with grep, but awk is designed for such tasks.
awk has numerous built in variables, FS=FieldSeperator, you can set that to any value, but here ‘\t’ is the C-language-like constant value representing the tab char. The ‘|’ (pipe) char is also popular.
BEGIN { ... code ... }is a block of code that executes before processing takes place.The final bit, is that code inside the non-BEGIN block, i.e.
{ if ( NF ... }is action that takes place for each line that is read.NF=Number(of)Fields. So you can easily filter by number of fields in a file.
NR=Number(of)Records.
Also note that for
greporawk, there is no need to usecat file | ..., both utiltites read any files that are passed in on the command line, i.e. grep …. file1 file2 … filenI hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.