1748142 Members
3542 Online
108758 Solutions
New Discussion юеВ

Re: files with hostname

 
SOLVED
Go to solution
Ralf Buchhold
Regular Advisor

files with hostname

Hello
I have one file on different servers like:
logfile1

I need a file with:
server1:logfile1 (here each line of logfile1)
server2:logfile1 (here each line of logfile1)
server3:logfile1 (here ....)

With cat logfile1 >> output I do not have the server-names.
Thanks for help
Ralf
4 REPLIES 4
Dietmar Konermann
Honored Contributor
Solution

Re: files with hostname

sed "s/^/$(hostname): /g" logfile1 >>output1
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Victor Fridyev
Honored Contributor

Re: files with hostname

Hi,

You can transform each file as follows:

awk '{print hn":"$0}' hn=$(hostname) logfile1 > logfile1.am

HTH
Entities are not to be multiplied beyond necessity - RTFM
Muthukumar_5
Honored Contributor

Re: files with hostname

we can do this as,

while read line; do
>echo $hostname:$line
>done < >

HTH.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: files with hostname

Change the script as,

while read line; do
echo `hostname`:$line
done < input > ouput

Else with perl script as,

perl -pe 's/^/'$(hostname)'/g' inputfile > outputfile
Easy to suggest when don't know about the problem!