I'm trying to figure out how to display the contents of a file through unix where the spaces and tabs are marked somehow. I know how to display the files with tabs (aka cat -T filename
) but I've been trying to figure out how to show the spaces as well. cat -A filename
doesn't work for me, and only replaces tabs with ^I
and places $
at the end of the line. How can I utilize cat
to print out a file with all tabs and spaces clearly marked?
Cat only provides -T (show tabs) or -E (show newlines) or -A (show both types).
cat is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to (con)catenate files (from Latin catenare, "to chain").
Cat(concatenate) command is very frequently used in Linux. It reads data from the file and gives their content as output. It helps us to create, view, concatenate files.
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à!)
There's a standard unix tool for character substitution. In this example, I'm replacing spaces for * and tabs for &:
$ cat tmp
space tab space tab end
tab space tab space end
$ cat tmp | tr " " "*" | tr "\t" "&"
space*tab&space&tab&end
tab&space&tab*space*end
The answer to your question: No, cat command can not "show" spaces as a visible characters. It just does not contain such a feature. Cat only provides -T (show tabs) or -E (show newlines) or -A (show both types).
I assume palako was meaning to say this, but instead he he jumped straight to providing you a workaround, which is valid. If you are looking to visually count spaces, that's fine. There are many workarounds, and not all will be appropriate for all users.
If you need something different, I suggest looking into Perl one-liners (because they could adapt easily into existing UNIX scripts), or write something in Python which mimics 'cat' but replaces spaces with another character, much like palako's "tr" example.
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