How to get the number of columns in a file in bash

To get the number of columns in a file in bash, we can use the awk command.

#awk '{print NF}' file | sort -nu | tail -n 1

Where 'file' is the name of the file for which the columns need to be counted.

 

Leave a Reply

Your email address will not be published. Required fields are marked *