Posted: . At: 8:58 AM. This was 4 years ago. Post ID: 14300
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Do not use cat when you can avoid it. This is very annoying.


The unneeded use of the cat command is very annoying, this is wasteful.

Something like this is very annoying to see.

cat unixhell.txt | sed 's/program/application/g'

Do it like this instead. This is the proper way to use sed.

sed 's/program/application/g' unixhell.txt

The user gets the same output but in one simple command. Unnecessary use of pipes and commands just makes a mess out of any one-liner.

This is a very annoying example.

cat file.txt | sort | uniq | sed 's/ic/uc/g' > file.txt

This can be shortened to this.

sed 's/ic/uc/g' unixhell.txt | sort | uniq

That is simpler and more attractive.

Another annoyance is using cat and piping it into grep. When you can just do this instead.

4.4 Mon May 11 jason@Yog-Sothoth 0: $ grep -n "file" linuxwords
11758:defile
16554:file
16555:filed
16556:filename
16557:filenames
16558:filer
16559:files
31928:profile
31929:profiled
31930:profiles
32312:pseudofiles
39817:subfile
39818:subfiles

Where linuxwords is the file I am looking in. This is a good way to keep your commands simple. Do not use uneeded commands if it is not required. Keep it as simple as possible.


1 thought on “Do not use cat when you can avoid it. This is very annoying.”

  1. I completely agree since I see it a lot at my workplace in people’s day tot day or in scripts obviously produced by the same individuals.

    Needless to say that people get defensive when you even mention this about their workflow.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.