Hi guys.
I have a file containing some hosts and their IPs.
host host1 192.168.2.10
host host2 192.168.2.11
host host3 192.168.2.12
I am writing a script where I want to print these values in 1 line. My script looks like
RUNTIME_NODE=`cat hosts.properties | grep host`
for i in $RUNTIME_NODE
do
echo $i | awk '{ print $1 $2 $3 }'
done
The output I am expecting is:
host host1 192.168.2.10
host host2 192.168.2.11
host host3 192.168.2.12
But the result I am getting is:
host
host1
192.168.2.10
host
host2
192.168.2.11
host
host3
192.168.2.12
How can I fix this ?
xbin
April 10, 2015, 3:49pm
2
To double space the file:
sed G FILE
Not quite following,
why not?
grep host hosts.properties | awk '{print $0"\n"}'
or simply
awk '/host/{print $0"\n"}'
xbin
April 10, 2015, 4:50pm
4
Why not
awk '/host/{print $0"\n"}' host.properties
or in sed
sed '/host/!d;G' host.properties
Of course there is no need to match a pattern if the file only needs double spacing.
Hi guys,
The issue is that I have 2 colums and I have to run 1 for loop for comparision purposes.
Column 1 contains
host1
host2
host3
Columns 2 contains
192.168.2.10
192.168.2.11
192.168.2.12
Combined file is:
host1 192.168.2.10
host2 192.168.2.11
host3 192.168.2.12
Now I ahve to run 1 for loop but I need 2 variables under that for loop. One variable takes first column and second variable takes second column RESPECTIVELY.
How can I do that ?
comparison of what? did you try the provided solutions?
RudiC
April 11, 2015, 7:07am
8
Does it?
For your problem in post#5, try
while read X HOST IP
do echo $HOST $IP
done < hostfile
and use the variables for your comparisons.