sed sed sed less sed's please

James McDonald james
Tue Nov 2 07:31:37 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
>  
>
Damn straight it helps... thanks very much David...




More information about the Linux-users mailing list