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.
-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.
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.
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.
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à!)
Use tr to discard everything except tabs, and then count:
< input-file tr -dc \\t | wc -c
Bash uses a $'...'
notation for specifying special characters:
grep -c $'\t' foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With