inside Habbie's mind

Unix trivia: echo cat | sed statement

written by peter, on May 24, 2010 8:48:00 AM.

I occasionally run into weird, funny or surprising aspects of Unix and Unix-like Operating Systems. I'll try to post about those regularly because they're fun.

This one popped up on irc a few weeks ago; a google search suggests it's at least 6 months old. I have been unable to track the original source down.

The question is: if you input echo cat | sed statement into your Unix shell, what comes out? Can you predict it? If not, can you try it and then explain it?

Comments

  • 'cement' is what comes out, because the 'a' in 'cat' is substituted with 'emen'. Any character other than backslash or newline can be used 't' instead of a slash to delimit the regular expression 'a' and the replacement 'emen'.

    Comment by Job — May 24, 2010 11:14:00 AM | # - re

  • statement has 3 t's, and comes after the s (which is a substitute operator). So the a in cat will be substituted with 'emen', which will yield 'cement' :)

    Comment by Emiel — May 24, 2010 11:16:31 AM | # - re

Leave a Reply