cat
From Initq
Contents |
cat and UUOC
UUOC (from comp.unix.shell on Usenet) stands for "Useless Use of cat". As received wisdom on comp.unix.shell observes, "The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process." Nevertheless one sees people doing
cat file | some_command and its args ...
instead of the equivalent and cheaper
<file some_command and its args ...
or (equivalently and more classically)
some_command and its args ... <file
Flags
Lets use cat to the fullest with it's built in flags. Our original file is
[alibaba@ohnonono junk]$ cat test.txt
line one
line two
line three
line four
If we need to line number the file we could use
[alibaba@ohnonono junk]$ cat -n test.txt
1 line one
2 line two
3
4
5 line three
6 line four
If wanted to line number only lines with content and also show end of line and tabs
[alibaba@ohnonono junk]$ cat -b -E -T test.txt
1 line one$
2 line two$
$
$
3 line three$
4 line^Ifour$
Show no blank line is not an option but you can use the -s flag to show only one blank line.
[alibaba@ohnonono junk]$ cat -s test.txt
line one
line two
line three
line four