Tuesday, March 22, 2005

behold the power of sed

I am an old unix hacker. I admit I get a thrill out of sed, awk, the shell and regular expressions. Here is an IM exchange I just had. Names changed to protect the innocent:

joe : got a second for a sed question?
el_jefe: uh-oh
el_jefe: ok
joe : I've got a filename, foo_293849723.txt, I want to rename it to foo.txt
el_jefe: ok
joe : so I want to strip everything from the _ to the .
el_jefe: ok
joe : I've stripped the _ and the ., but not the stuff in between
el_jefe: sed 's/_.*\./\./' ?
joe : that's it!
el_jefe: whew
el_jefe: good to know i can still do that
joe : I'm going to stare at that one for a while and figure out how it's any different from what I was trying
el_jefe: good luck

1 comment:

  1. And it turned out to be a single \ that made the difference. Sometimes you just need a new set of eyes to look at a problem.

    -Joe :)

    ReplyDelete