问题描述:

I Need to write the script to count the number of tabs in each line in file and print the output to text file(output.txt).

how to do this?

网友答案:
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
网友答案:

sed 's/[^\t]//g' input.txt | awk '{ print length }' > output.txt

Based on this answer.

网友答案:

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
相关阅读:
Top