[英]How to count number of tabs in each line using shell script?
I need to write a script to count the number of tabs in each line of a file and print the output to a text file (eg, output.txt). 我需要编写一个脚本来计算文件每行中的选项卡数量,并将输出打印到文本文件(例如output.txt)。
How do I do this? 我该怎么做呢?
awk '{print gsub(/\t/,"")}' inputfile > output.txt
如果将\\t
视为字段分隔符,则每行上的字段数将少于\\t
:
awk -F'\t' '{ print NF-1 }' input.txt > 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
基于这个答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.