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

cat abc.txt | sed -e 's/^host=atlx3.*/#&\n&/'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.