Operating System - HP-UX
1753797 Members
7820 Online
108799 Solutions
New Discussion юеВ

How can I do this in Unix ?

 
SOLVED
Go to solution
Rob Johnson_3
Regular Advisor

How can I do this in Unix ?

I have a file that contains several hundred hostnames:
host1.domain.com
host2.domain.com
host3.domain.com
I need to put all hosts on one line and serate the name with a colon to look like this:
host1.domain.com:host2.domain.com:host4.domain.com.
How can I read the hostnames from a file and seperate them with a colon?
5 REPLIES 5
H.Merijn Brand (procura
Honored Contributor
Solution

Re: How can I do this in Unix ?

# perl -pe's/\n/:/' file

Enjoyn Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Rob Johnson_3
Regular Advisor

Re: How can I do this in Unix ?

That did it!

Thank you.
Nguyen Anh Tien
Honored Contributor

Re: How can I do this in Unix ?

I just use:
#cat oldfile|awk '{printf("%s"":",$1)}'>newfile


HTH
tienna
HP is simple
Marton Ferenc
Advisor

Re: How can I do this in Unix ?

for i in `cat file`; do echo -n $i ""; done; echo;

J5000
Arturo Galbiati
Esteemed Contributor

Re: How can I do this in Unix ?

Hi,
%cat tt
a
b
# change new line to ':'
%list=$(tr -s '\n' ':'
# Remove last ':'
echo ${list%%:}
a:b

HTH,
Art