LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-16-2005, 10:43 PM   #1
frostillicus
Member
 
Registered: Jul 2004
Location: Florida
Distribution: Slackware
Posts: 32

Rep: Reputation: 15
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.
 
Old 04-16-2005, 10:59 PM   #2
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
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.
 
Old 04-16-2005, 11:04 PM   #3
frostillicus
Member
 
Registered: Jul 2004
Location: Florida
Distribution: Slackware
Posts: 32

Original Poster
Rep: Reputation: 15
yes it does, works like a champ. excellent. muchos gracias.
 
Old 04-17-2005, 12:36 AM   #4
frostillicus
Member
 
Registered: Jul 2004
Location: Florida
Distribution: Slackware
Posts: 32

Original Poster
Rep: Reputation: 15
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
process substitution jk3us Linux - Software 1 12-02-2004 04:34 PM
sed substitution error BlkPoohba Programming 1 08-25-2004 02:00 PM
Is there any substitution to Ghost? Swift&Smart Linux - Software 12 06-22-2004 05:31 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
OS Conditional Defines kevin.cowley Programming 1 09-24-2003 03:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration