5

What bash command can be used for regex substitution on a pipe?

     cat foo.txt | someprogram

3 Answers 3

11

You probably want

sed 's/exp1/exp2/g' foo.txt > foo2.txt

Read more at Sed tutorial, Another tutorial, and A small tutorial at Linux HOWTOs

1
  • sed isn't just a program, it's a way of life. Jun 15, 2009 at 11:24
4

You can also use perl one liners if you find you want more regular expression features than sed provides. See this link for a comparison. nik's example would look like:

perl -ple 's/exp1/exp2/g' foo > foo2.txt
1
  • I recently discovered perl -pe, and it's great to have a much more powerful regex engine available :) Jan 22, 2010 at 15:10
1

The program you are looking for is sed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .