sed sed sed less sed's please

James McDonald james
Fri Nov 5 16:24:12 PST 2004


David Bandel wrote:

>On Tue, 2 Nov 2004 16:09:48 +1100, James McDonald
><james at jamesmcdonald.id.au> wrote:
>  
>
>> 
>>I am trying to do a multiple find and replace in a text file I have the
>>following code... which is a series of piped sed's 
>>  
>>can anyone show me a better way I'm hoping there is a way to do the whole 3
>>replacements with one call to sed? 
>>  
>>$ cat test.fw | sed -e 's/INPUT/CUSTOMINPUT/g' \ 
>>| sed -e 's/OUTPUT/CUSTOMOUTPUT/g' \ 
>>| sed -e 's/FORWARD/CUSTOMFORWARD/g' > test2.fw 
>>    
>>
>
>You have two options in this case:
>1.  change to a multiple sed syntax:
>     a.  put -e before each instruction:
>           sed -e 's/OUTPUT/CUSTOMOUTPUT/g' -e 's/INPUT/CUSTOMINPUT/g'
>test.fw > test2.fw
>     b. use semicolons between instructions:
>           sed -e 's/OUTPUT/CUSTOMOUTPUT/g ; s/INPUT/CUSTOMINPUT/g'
>test.fw > test2.fw
>(note how and where to use the ' to surround sed instructions; also
>note I didn't use cat and a pipe).
>
>2.  use a sed script:
>---begin script---
>     s/INPUT/CUSTOMINPUT/g
>     s/OUTPUT/CUSTOMOUTPUT/g
>---end script--
>    sed -f sedscript test.fw > test2.fw
>
>hth,
>
>David A. Bandel
>  
>
David I didn't know you where famous until I opened up a copy of linux 
journal and it had your name scattered throughout... It took me a 
moment.... I'm like "David A. Bandel, David A Bandel" now where the heck 
have I.... "Linux-Users" sheesh. This list has a lot of contributors  to 
OSS.




More information about the Linux-users mailing list