Results 1 to 3 of 3
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 ...
- 05-14-2008 #1Just Joined!
- Join Date
- May 2008
- Posts
- 1
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
- 05-14-2008 #2Code:
awk>output.txt '/host=atlx3 sid=atld3/{print "#"$0}1' abc.txt
- 05-17-2008 #3Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Or
Less to type, and you can use the -i flag and drop the output redirect to make the change straight to the input file.Code:sed 's/host=atlx3 sid=atld3.*/#&/' abc.txt >output.txt
Interesting that neither of the solutions uses the asked-for grep, since that's an inappropriate tool for this problem.


Reply With Quote