Re: files with hostname (311 Views)
Reply
Regular Advisor
Ralf Buchhold
Posts: 243
Registered: ‎02-26-2004
Message 1 of 5 (311 Views)
Accepted Solution

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
Honored Contributor
Dietmar Konermann
Posts: 1,207
Registered: ‎02-04-1998
Message 2 of 5 (311 Views)

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
Victor Fridyev
Posts: 937
Registered: ‎07-01-1998
Message 3 of 5 (311 Views)

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
Muthukumar_5
Posts: 4,030
Registered: ‎06-09-2004
Message 4 of 5 (311 Views)

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!
Honored Contributor
Muthukumar_5
Posts: 4,030
Registered: ‎06-09-2004
Message 5 of 5 (311 Views)

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!
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.