Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

files with hostname

SOLVED
Go to Solution
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
Honored Contributor Honored Contributor

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)
Honored Contributor 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
Honored Contributor 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!
Highlighted
Honored Contributor 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!