Operating System - HP-UX
1825764 Members
2047 Online
109687 Solutions
New Discussion

include servername infront of each line of file

 
SOLVED
Go to solution
Petr Simik_1
Valued Contributor

include servername infront of each line of file

Hi,
A want to output files and include in front of each line server_name or some other specific string.
for example

"syntax" passwd
server1 root,*,123,.....
server1 adm,2,332,.....
..
.

What is the syntax?
Thank you
Petr
4 REPLIES 4
Fred Ruffet
Honored Contributor
Solution

Re: include servername infront of each line of file

in shell :
for i in `cat passwd`
do
echo server_name $i
done

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Bharat Katkar
Honored Contributor

Re: include servername infront of each line of file

Hi,
Not sure if i got your question correctly!!

What is the syntax?
syntax is "$hostname"

Regards,

You need to know a lot to actually know how little you know
Slawomir Gora
Honored Contributor

Re: include servername infront of each line of file

Hi,

you can try:

cat /etc/passwd | awk -v H=`hostname` '{printf "%s %s\n", H, $0}'
Petr Simik_1
Valued Contributor

Re: include servername infront of each line of file

than you awk verison works.
I use it as folows:

for i in serverlist
do
remsh $i "your_comnd..../etc/passwd |awk ..."
done

than I can get output of same file from different servers and make comparations afterwards.