Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count number of tab characters in linux

Tags:

grep

bash

unix

csh

I want to count the numbers of hard tab characters in my documents in unix shell.

How can I do it?

I tried something like

grep -c \t foo

but it gives counts of t in file foo.

like image 657
ravi Avatar asked Jun 14 '12 14:06

ravi


People also ask

How do I count characters in Linux?

-m: Using -m option 'wc' command displays count of characters from a file. 5. -L: The 'wc' command allow an argument -L, it can be used to print out the length of longest (number of characters) line in a file.

How many spaces is a tab Unix?

By default, in most terminals, the tab stops are 8 columns apart, but that's configurable. Only the terminal knows how many columns to the right a TAB will move the cursor. You can get that information by querying the cursor position from the terminal before and after the tab has been sent.

What is the count command in Linux?

The easiest way to count files in a directory on Linux is to use the “ls” command and pipe it with the “wc -l” command. The “wc” command is used on Linux in order to print the bytes, characters or newlines count.

How do I find tabs in Linux?

just use grep "<Ctrl+V><TAB>" , it works (if first time: type grep " then press Ctrl+V key combo, then press TAB key, then type " and hit enter, voilà!)


2 Answers

Use tr to discard everything except tabs, and then count:

< input-file tr -dc \\t | wc -c
like image 182
William Pursell Avatar answered Sep 19 '22 17:09

William Pursell


Bash uses a $'...' notation for specifying special characters:

grep -c $'\t' foo
like image 30
chepner Avatar answered Sep 18 '22 17:09

chepner