LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed substitution conditional (https://www.linuxquestions.org/questions/linux-newbie-8/sed-substitution-conditional-314030/)

frostillicus 04-16-2005 10:43 PM

sed substitution conditional
 
on lines beginning with echo, globally substitute text with subtext:

sed '/^echo/s/text/subtext/g'

ok, i got that. what i want to do is to wrap ^echo into a not! conditional:

sed '/!(^echo)/s/text/bustext/g'

wondering what the syntax would be to make it like that... i can exclude based on the first character:

sed '/^[^e]/s/text/bustext/g'

but then lines beginning with en, etc., are also excluded. i would like to be able to exclude based on a pattern at the beginning of a line, not just a character. i've tried lostsa syntactical? combinations, nothing seems to work... thanks.

frob23 04-16-2005 10:59 PM

You're going about it in the right manner but in the wrong place.

Try
Code:

sed '/^echo/!s/text/subtext/g'
What this does is look at each line, if it starts with "echo" it does NOT replace text with subtext. For those lines which don't start with "echo" it does make the substitution.

I hope this meets your needs.

frostillicus 04-16-2005 11:04 PM

yes it does, works like a champ. excellent. muchos gracias.

frostillicus 04-17-2005 12:36 AM

naturally, an hour later i find the exact answer frob gave while looking for something else... the !s syntax is listed in a great sed one-liners file that i already had a copy of..:

http://www.student.northpark.edu/pem...d/sed1line.txt

i had looked, can't believe i missed it. doh...


All times are GMT -5. The time now is 09:04 AM.