How to count number of tabs in each line using shell script?
If you treat \t
as the field delimiter, there will be one fewer \t
than fields on each line:
awk -F'\t' '{ print NF-1 }' input.txt > output.txt
sed 's/[^\t]//g' input.txt | awk '{ print length }' > output.txt
Based on this answer.
awk '{print gsub(/\t/,"")}' inputfile > output.txt
This will give the total number of tabs in file:
od -c infile | grep -o "\t" | wc -l > output.txt
This will give you number of tabs line by line:
awk '{print gsub(/\t/,"")}' infile > output.txt