Friday, April 4, 2014

appending string after end of each line

I have a File that contains list of servers and I just want to append a domain-name (say .xyz.com ) at the end of line.

# head -5 serverlist.txt
server1
server2
server3
server4
server5
# sed  -ie 's/$/.xyz.com/' serverlist.txt
# head -5 serverlist.txt
server1.xyz.com
server2.xyz.com
server3.xyz.com
server4.xyz.com
server5.xyz.com
#

Another method using Awk:
awk '{ print $0 ".xyz.com" }' < serverlist.txt > resultfile.txt

No comments:

Post a Comment

Popular Posts

About Me

My photo
I have started this blog to share my work experience and spread some smart solutions on Linux to Internet community. I'm hoping more people will get benefited from this blog. Brief about me: I have 14+ years experience working as System Admin and currently work with VMware.