Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'View a Lord of the Rings timeline easter egg in calendar' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View a Lord of the Rings timeline easter egg in calendar
Authored by: merlyn on Jan 13, '04 11:26:56AM

cat /usr/share/calendar/calendar.history | grep "LOTR"
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:

grep LOTR /usr/share/calendar/calendar.history
Almost every use of "cat SINGLEFILE | ...somecommand..." is wrong. Learn!

[ Reply to This | # ]
View a Lord of the Rings timeline easter egg in calendar
Authored by: SOX on Jan 13, '04 12:11:06PM

How about
cat somefile | cpio



[ Reply to This | # ]
View a Lord of the Rings timeline easter egg in calendar
Authored by: Djehuti on Jan 13, '04 12:13:58PM

cpio < somefile



[ Reply to This | # ]
View a Lord of the Rings timeline easter egg in calendar
Authored by: foobar104 on Jan 13, '04 02:47:12PM
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.

[ Reply to This | # ]

View a Lord of the Rings timeline easter egg in calendar
Authored by: SeanAhern on Jan 13, '04 04:52:03PM
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.

---
-Sean

[ Reply to This | # ]

View a Lord of the Rings timeline easter egg in calendar
Authored by: ToadSprocket on Jan 13, '04 03:27:00PM

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.



[ Reply to This | # ]
View a Lord of the Rings timeline easter egg in calendar
Authored by: lukec on Jan 13, '04 04:15:08PM

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.

Consider that the novice CL user will get much faster results if they program in a way that is intuitive to them. The 5 additional miliseconds it takes to spawn an additional instance of cat is quite negligable compare to the 5 extra seconds it would take to change their original code to adhere to the 'correct' way of doing things.

You want speed ? program in C or assembly.

All who are new to the command line - Keep up the good work!

Luke



[ Reply to This | # ]
View a Lord of the Rings timeline easter egg in calendar
Authored by: dhrakar on Jan 13, '04 08:55:42PM
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.

[ Reply to This | # ]
View a Lord of the Rings timeline easter egg in calendar
Authored by: fuerst on Jan 15, '04 06:14:17AM
alias gethist 'grep \!^ /var/log/foo.log' would do the same, but optimized.

[ Reply to This | # ]
View a Lord of the Rings timeline easter egg in calendar
Authored by: fuerst on Jan 15, '04 06:17:09AM
Try
alias gethist 'grep \!^ /var/log/system.log'
. I forgot the backslash away in my first post..

[ Reply to This | # ]
View a Lord of the Rings timeline easter egg in calendar
Authored by: VEGx on Jan 14, '04 11:07:00AM

cat file | grep "word"

It maybe "useless" in most times, but it's handy sometimes. For me at least. this way I can just hit up-arrow and modify the last word... I hate to "navigate" in the command line... if it's a word in the middle it's such a pain...
[Read: I grep often `edict' the english/Japanese dictionary and Terminal.app doesn't like the multi column glyphs all that much... so you are navigating "blindly" because were you see the cursor is not where you really are...]



[ Reply to This | # ]