BladeSystem Forums Have Moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
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

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

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

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

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!