07-28-2011
From Bash cookbook:
Useless Use of cat
Certain Unix users take a positively giddy delight in pointing out inefficiencies in
other people's code. Most of the time this is constructive criticism gently given and
gratefully received.
Probably the most common case is the so-called “useless use of cat award” bestowed
when someone does something like cat file | grep foo instead of simply grep foo
file. In this case, cat is unnecessary and incurs some system overhead since it runs in
a subshell. Another common case would be cat file | tr '[A-Z]' '[a-z]' instead of
tr '[A-Z]' '[a-z]' < file. Sometimes using cat can even cause your script to fail (see
Recipe 19.8, “Forgetting That Pipelines Make Subshells”).
But... (you knew that was coming, didn't you?) sometimes unnecessarily using cat
actually does serve a purpose. It might be a placeholder to demonstrate the fragment
of a pipeline, with other commands later replacing it (perhaps even cat -n). Or it
might be that placing the file near the left side of the code draws the eye to it more
clearly than hiding it behind a < on the far right side of the page.
While we applaud efficiency and agree it is a goal to strive for, it isn't as critical as it
once was. We are not advocating carelessness and code-bloat, we're just saying that
processors aren't getting any slower any time soon. So if you like cat, use it.
The good book, btw.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
using grep, i have a file emp.lst, and i want all those records
where "S" or "s" (capital or small) is not there
i used this
grep emp.lst
when i use grep emp.lst
i am getting rows with S..but why negate (^) is not working? (3 Replies)
Discussion started by: soujanya_srk
3 Replies
2. UNIX for Dummies Questions & Answers
I have a file that has the following:
591066 100.0
591066 100.0
591066 100.0
591066 100.0
591066 100.0
591066 100.0
591066 100.0
591066 100.0
591066 100.0
591066 100.0
591066 100.0
... (5 Replies)
Discussion started by: Pablo_beezo
5 Replies
3. Shell Programming and Scripting
<record>
<set>
<termId>1234</termId>
<termType>First</termType>
</set>
<set>
<termId>5678</termId>
<termType>Second</termType>
</set>
</record>
This is saved in record.xml
Hi
I have this sample XML that i am grepping using a shell program.
The objective of the task is - based... (7 Replies)
Discussion started by: revertback
7 Replies
4. Shell Programming and Scripting
The below command is not working
stackmem="$(pmap $1 | grep -i '' | awk '{print $2}'| tr -d ' K')"
I need to grep strictly for ---->
Regards,
Mohtashim (2 Replies)
Discussion started by: mohtashims
2 Replies
5. Shell Programming and Scripting
Hi All
I have a file containing following records:
$HEW_TGT_DB2_USER=hbme_bi2
$prmAttunityUser=ais
$DS_USER=hbme_bi2
$prmStgUser=hbme_bi2
$prmuser=hbme_bi2
$prmStgPass=hbme_bi2
$prmpwd=hbme_bi2
$prmAttunityUser=ais
Say suppose the name of the file is test4.txt
When i fire this... (2 Replies)
Discussion started by: vee_789
2 Replies
6. Shell Programming and Scripting
i have following pattern in file
s6:s2
s2:s4
s1:s2:s3:s4:s5:s6
s1
.
.
Now i want to find occurence of each record in file like s6:s2 occurs twice {once in first record and both occur in 3 record as well}
so output should be
s6:s2 2
s2:s4 2
s1:s2:s3:s4:s5:s6 :1
s1 : 2
... (7 Replies)
Discussion started by: sharad.40216
7 Replies
7. Shell Programming and Scripting
Hi Guys,
I am new to shell scripting. Need help on grep command. I had a file called file.log which contain below statements.
12 Nov 2013 14:12:17,756 INFO security - Userid: raja, Saved File Instance, Name: , Registry:
23 Nov 2013 14:14:11,777 INFO security - Userid: raja, Saved... (7 Replies)
Discussion started by: Vinoth Kumar G
7 Replies
8. UNIX for Dummies Questions & Answers
HI,
I have a command to check a license file.
License_print.
In that file you get the headlines and all different licenses.
Now i want to have things extracted from it.
so i do like following:
license_print | grep -iw -e "user" -e "admin"
But i don´t want all lines where user is... (11 Replies)
Discussion started by: Tzwaj
11 Replies
9. Shell Programming and Scripting
Hello, I have an input file that looks like so:
LDLR
LDLRAD4
VLDLR
when I grep "LDLR" I get an output of:
LDLR
LDLRAD4
VLDLR
Since all names have "LDLR" included within them, but all I want the output to be is
LDLR
I know it can work if I surround the words with pipes for... (5 Replies)
Discussion started by: Rabu
5 Replies
10. UNIX for Dummies Questions & Answers
Hi guys,
Hope someone can help me with this - I'm sure it's fairly simple but it's driving me mad! (forgive the coding - still new on scripting - come from Windows)
I have the following coding for checking whether I want to include a line in a file:-
EXTRACT_Date=$(date --date="${PERIOD}"... (6 Replies)
Discussion started by: NickF
6 Replies
GZEXE(1) General Commands Manual GZEXE(1)
NAME
gzexe - compress executable files in place
SYNOPSIS
gzexe [ name ... ]
DESCRIPTION
The gzexe utility allows you to compress executables in place and have them automatically uncompress and execute when you run them (at a
penalty in performance). For example if you execute ``gzexe /bin/cat'' it will create the following two files:
-r-xr-xr-x 1 root bin 9644 Feb 11 11:16 /bin/cat
-r-xr-xr-x 1 bin bin 24576 Nov 23 13:21 /bin/cat~
/bin/cat~ is the original file and /bin/cat is the self-uncompressing executable file. You can remove /bin/cat~ once you are sure that
/bin/cat works properly.
This utility is most useful on systems with very small disks.
OPTIONS
-d Decompress the given executables instead of compressing them.
SEE ALSO
gzip(1), znew(1), zmore(1), zcmp(1), zforce(1)
CAVEATS
The compressed executable is a shell script. This may create some security holes. In particular, the compressed executable relies on the
PATH environment variable to find gzip and some other utilities (tail, chmod, ln, sleep).
BUGS
gzexe attempts to retain the original file attributes on the compressed executable, but you may have to fix them manually in some cases,
using chmod or chown.
GZEXE(1)