Stop piping cat into grep

Posted in rant

squirrelWhy ‘cat’ something and then pipe it into grep to search for something when grep can easily search a file/dir/wild card all by itself? It’s like taking your car to the dealership so you can change your own oil. What? No, that doesn’t really make any sense, but neither does piping cat into grep.

If you’re dealing with large files or complicated expressions, the reason you shouldn’t cat something into a pipe just to grep it becomes obviously clear.

# cd /var/log/httpd/

Lets look at some apache logs for example.

# time cat * | grep root

real 0m0.018s
user 0m0.0012s
sys 0m0.006s

# time grep root *

real 0m0.009s
user 0m0.006s
sys 0m0.003s

The savings of a fraction of a second isn’t the point. It’s just a silly way to go about doing it. It’s not the end of the world, just plain old inefficient logic at work. Watching someone do this is almost as annoying as seeing them run “rm -rf” when they’re deleting a single file.

I just read a few posts on some forums where people complained about people that don’t like piping cat into grep, so I thought I’d feed the fire! :) Hopefully the time illustration shows you that catting huge logs really doesn’t matter anymore. Gotcha ibtch!

Posted by admica   @   12 February 2010
Tags : , ,

Related Posts

Like this post? Share it!

Digg Twitter StumbleUpon Delicious Technorati Facebook RSS

4 Comments

Comments
Feb 12, 2010
4:08 pm
#1 wut :

Who the hell cares how other people (ab)use pipes?

Feb 16, 2010
8:57 am
#2 admica :

tl;dr? I was joking, I agree.

Trackbacks to this post.
  1. uberVU - social comments
  2. Warum denn immer cat *.txt | grep bla ? ยป Bananas Development Blog
Leave a Comment

Name

Email

Website

Previous Post
« ATI fglrx driver - fix corrupt amdpcsdb
Next Post
Steganography with a deck of playing cards »
Powered by Wordpress   |   Lunated designed by ZenVerse