|
|
View a Lord of the Rings timeline easter egg in calendar
That's what we call in the business a Useless Use of Cat. Perhaps to speed up both your fingers and your computer, you could have typed that as:
Almost every use of "cat SINGLEFILE | ...somecommand..." is wrong. Learn!
View a Lord of the Rings timeline easter egg in calendar
How about
View a Lord of the Rings timeline easter egg in calendar
cpio < somefile
View a Lord of the Rings timeline easter egg in calendar
Almost every use of "cat SINGLEFILE | ...somecommand..." is wrong. Learn!
If anybody was wondering why UNIX hasn't taken over the world, there you go. There is absolutely nothing wrong about this use of cat. No, it's not necessary, but it works just fine. In this particular instance, it's my preferred idiom for searching a single file, because I can't reliable remember whether grep's command-line syntax is "grep pattern file" or "grep file pattern." In other words, I can't remember whether to think "search for this in that" or "search that for this." With cat and a pipe, I don't have to. UNIX is great. UNIX is fantastic. People who look at a perfectly good way of doing something with UNIX and fly off the handle, call it wrong, and command those who use it to "Learn!" kinda suck, however.
View a Lord of the Rings timeline easter egg in calendar
I can't reliable remember whether grep's command-line syntax is "grep pattern file" or "grep file pattern."
Here's a way that I remember. Grep searches multiple files for one pattern. That means that you specify the pattern first, then a bunch of files. "grep pat *" searches all files for the pattern "pat". With this in mind, it's relatively easily to reminder, since "grep * pat" is simply never seen. Don't know if this helps, but it works for me. ---
View a Lord of the Rings timeline easter egg in calendar
Define Wrong. Did it Work? Yes. That's the beauty of UNIX, so many ways to get the job done. Consider that maybe he didn't know what he was grepping for in the first place. He 'cat's the file, then sees the "LOTR" string, hits up arrow, and tags his '| grep' command at the end of his previous command. Anyhow... who cares. Get off your high horse.
View a Lord of the Rings timeline easter egg in calendar
You're right in that it is unnecessary to use 'cat' in many cases. If I were writing a shell script I would be very scrutinous of the excessive usage of 'cat' or 'grep' or 'awk' (or any other tool) especially in a loop. With experience comes a more evolved usage of the command line.
View a Lord of the Rings timeline easter egg in calendar
Another perfectly valid reason to use cat foo | grep is when you need an alias for quickly getting information out of a log. For example, I have several aliases (I use the AT&T ksh for my shell) that look like:
alias gethist 'cat /var/log/foo.log | grep'This allows me to type only gethist dude to grep 'dude' out of the foo.log log. Saves typing the log path out...Another use is for looking into files that I do not have read permission on (I'm a user consultant here at work and frequently need to look at user and/or system files). Since I do not have sudo (e.g. root) access to the grep command, I often wind up doing sudo cat /root/owned/file | grep foo. This way only cat has to run as root.
View a Lord of the Rings timeline easter egg in calendar
alias gethist 'grep \!^ /var/log/foo.log' would do the same, but optimized.
View a Lord of the Rings timeline easter egg in calendar
Try
. I forgot the backslash away in my first post..
View a Lord of the Rings timeline easter egg in calendar
cat file | grep "word" |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.08 seconds |
|