![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| copy and paste a specific line | tiger99 | Shell Programming and Scripting | 7 | 02-24-2008 07:43 AM |
| VNC copy paste problem | param_it | Windows & DOS: Issues & Discussions | 0 | 07-26-2007 11:43 PM |
| cut, copy + paste | aitor314 | UNIX for Dummies Questions & Answers | 2 | 02-06-2006 01: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 12:27 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi era / Scripting experts
I still help to know how to reverse the process.. Thanks in advance |
| Forum Sponsor | ||
|
|
|
|||
|
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
Code:
sed '/mail=DISABLE$/{;N;s/.*\n#//;}' abc.txt
|
|
|||
|
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. |
|
|||
|
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.... |
|||
| Google UNIX.COM |