![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | 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. Shell Script Page. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| 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 |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
How to copy and paste line in shell script
Hi
I want to grep for a line and copy and paste that line. for Example ---- file 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 file abc.txt ---- Now I want to grep line with host=atlx3 and sid=atld3 and copy and paste the line and ALSO put "#" in front of one of the line. The following is the output I would like to see... ---- file output.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=atlx3 sid=atld3 mail=def@abc.com host=atlx4 sid=atld4 mail=mno@abc.com --- end of file output.txt ---- How can I do this in shell script. Thanks in advance for your help. RK |
| Forum Sponsor | ||
|
|
|
|||
|
Assuming this precise sequence of host and sid is the deciding criterion, maybe something like
Code:
sed '/host=atlx3 sid=atld3/{;h;s/^/#/p;x;}' abc.txt
|
|
|||
|
Thank You, works perfectly....
Sincere apologies for asking another question but I am very new to scripting and need some HELP. Question: How to reverse it.. means find the line with host=atlx3 sid=atld3 and mail=DISABLE and then delete this line and at the same time un-comment ('#') the line above it.. --- INPUT.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=atlx3 sid=atld3 mail=DISABLE host=atlx4 sid=atld4 mail=mno@abc.com ------------------------- ---- OUTPUT.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 -------------------- |
|||
| Google UNIX.COM |