Register
It is currently Wed Oct 22, 2014 4:24 pm

using sed to get matched word, but ignore empty space


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Feb 25, 2013 4:05 pm   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 36
I need the sed syntax that searches for a pattern, but only changes those patterns that don't have a space after the = sign... for instance; this is file1.cgf:
Code:
#today= (this can be any day of the week)
#examples of today are Monday, Tuesday, etc
today=Monday

Now, I need to be able to change whatever day that comes after the uncommented "today=" at the end of the file to Saturday, but ignore the first "today= (this can be...blah)" since it has a space after the = sign.

I have got this so far to ignore the space, but it ignores the "today=Monday" as well.
Code:
sed -i 's/today=![\s ]/today=Saturday/' file1.cfg

...and if I do this:
Code:
sed -i 's/today=[\s ]*/today=Saturday/' file1.cfg

I get this:
Code:
#today=Saturday(this can be any day of the week)
#examples of today are Monday, Tuesday, etc
today=SaturdayMonday

and I need it to be:
Code:
#today= (this can be any day of the week)
#examples of today are Monday, Tuesday, etc
today=Saturday

Keep in mind that it might not always be the last instance that I need replaced and there might be multiple "today=Monday" in the file... I just need to change anything that doesn't have a space after the = sign.

Thanks.


Top
 Profile  
 PostPosted: Mon Feb 25, 2013 5:17 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
hello,

Code:
sed 's/^\(today=\)[^ ].*/\1Saturday/' UrFile
#today= (this can be any day of the week)
#examples of today are Monday, Tuesday, etc
today=Saturday
[^ ] is "not space"


Top
 Profile  
 PostPosted: Mon Feb 25, 2013 5:31 pm   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 36
thanks! It works perfectly! :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP