Find Number of fields in a file

To find the number of fields in a TSV file just do the following:

First calculate the number of tabs:

$ head -1 /tmp/file.txt |  egrep -o -E $'\t' | wc -l
16

The number of fields is number of tabs separating the fields + 1

16 + 1 = 17

 
0
Kudos
 
0
Kudos

Now read this

Streaming data to Hadoop using Unix Pipes? Use Pipefail

If you pipe the output of a statement to hadoop streaming you must know about the unix pipefail option. To demonstrate what it does, try this out in your commandline: $> true | false $> echo $? 1 $> false | true $> echo $? 0... Continue →