5

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

     cat foo.txt | someprogram
Alex
  • 2,357
  • 5
  • 32
  • 41

3 Answers3

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

nik
  • 7,100
  • 2
  • 25
  • 30
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
Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
1

The program you are looking for is sed.

David Pashley
  • 23,497
  • 2
  • 46
  • 73