The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
VNC copy paste problem param_it Windows & DOS: Issues & Discussions 2 1 Week Ago 05:02 AM
copy and paste a specific line tiger99 Shell Programming and Scripting 7 02-24-2008 08:43 AM
cut, copy + paste aitor314 UNIX for Dummies Questions & Answers 2 02-06-2006 02:17 AM
copy and paste from MS Windows to Unix Loaded Gun UNIX for Dummies Questions & Answers 9 06-02-2003 02:12 AM
Cut, Copy and Paste with X auswipe UNIX Desktop for Dummies Questions & Answers 4 03-27-2002 01:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 9
Hi era / Scripting experts

I still help to know how to reverse the process..

Thanks in advance
Reply With Quote
Forum Sponsor
  #9  
Old 05-15-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
It's not allowed to bump up questions! Please read the rules.
Reply With Quote
  #10  
Old 05-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
It would be easier if the comment could go after the DISABLE line; is this an option?

Code:
sed '/host=atlx3 sid=atld3/{;h;s/mail=.*/mail=DISABLE/p;x;s/^/#/;}' abc.txt
to disable and

Code:
sed '/mail=DISABLE$/{;N;s/.*\n#//;}' abc.txt
to enable again (assuming your sed understands \n).
Reply With Quote
  #11  
Old 05-16-2008
Registered User
 

Join Date: Jun 2007
Location: Beijing China
Posts: 495
Code:
cat filename | sed '/host=atlx3 sid=atld3/p' | awk 'BEGIN{n=0}
{
if (index($0,"host=atlx3 sid=atld3")!=0 && n==0)
{
        print "#"$0
	n=1
}
else
	print
}'
Reply With Quote
  #12  
Old 05-16-2008
Registered User
 

Join Date: May 2008
Posts: 9
Yes, the comment could go after the DISABLE line but in the second part of the sed command if there are multiple entries with comment '#' and DISABLE THEN I want to un-comment and delete the DISABLE line based on certain host and sid.

for example:
**********
--- start of abc.txt ----
host=atlx1 sid=atld1 mail=abc@abc.com
host=atlx2 sid=atld2 mail=xyz@abc.com
host=atlx3 sid=atld3 mail=def@abc.com
host=atlx4 sid=atld4 mail=mno@abc.com
------- end of abc.txt --------

Then I issue the command

sed '/host=atlx3 sid=atld3/{;h;s/mail=.*/mail=DISABLE/p;x;s/^/#/;}' abc.txt

then I issue the command for another host and sid

sed '/host=atlx4 sid=atld4/{;h;s/mail=.*/mail=DISABLE/p;x;s/^/#/;}' abc.txt

after issuing the above two commands, here's the NEW abc.txt file

----- start of NEW abc.txt ----
host=atlx1 sid=atld1 mail=abc@abc.com
host=atlx2 sid=atld2 mail=xyz@abc.com
host=atlx3 sid=atld3 mail=DISABLE
#host=atlx3 sid=atld3 mail=def@abc.com
host=atlx4 sid=atld4 mail=DISABLE
#host=atlx4 sid=atld4 mail=mno@abc.com

------ end of NEW abc.txt -------

NOW I want to uncomment the entry for host=atlx3 sid=atld3 and remove the line with host=atlx3 sid=atld3 and mail=DISABLE.

Hope I am clear with my requirement.

Again THANK YOU so much for your help.
Reply With Quote
  #13  
Old 05-16-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
sed '/host=atlx3 sid=atld3 mail=DISABLE$/{;N;s/.*\n#//;}' abc.txt
Reply With Quote
  #14  
Old 05-16-2008
Registered User
 

Join Date: May 2008
Posts: 9
Thanks era, it works but there are still some issues.

if there's more than one blank space between host and sid then it does not work AND also if there are more than one line with the same host and sid it comments '#' all lines having the given host, sid.

for example
*********

----- abc.txt -----
host=atlx1 sid=atld1 mail=abc@abc.com
host=atlx2 sid=atld2 mail=xyz@abc.com
host=atlx3 sid=atld3 purpose=development
host=atlx3 sid=atld3 mail=def@abc.com

host=atlx4 sid=atld4 mail=mno@abc.com
---- end of abc.txt ----

by running the command ....

sed '/host=atlx3 sid=atld3/{;h;s/mail=.*/mail=DISABLE/p;x;s/^/#/;}' abc.txt

it gives the following output...

host=atlx1 sid=atld1 mail=abc@abc.com
host=atlx2 sid=atld2 mail=xyz@abc.com
#host=atlx3 sid=atld3 purpose=development
host=atlx3 sid=atld3 mail=DISABLE
#host=atlx3 sid=atld3 mail=def@abc.com
host=atlx4 sid=atld4 mail=mno@abc.com

it should not comment '#' the line shown in red above (with purpose=development)


Again Thank You so much for your help, without your help I would still be reading the man pages....
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 01:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0