Experts,
At the moment I am working in AIX box where sed -i is not available.
My requirement is as below
Two files file1 and file2. file1 contains the IP address, its count. file2 contains the Hostname and its corresponding IP address. I would like get the IP address replaced with the apt Hostname in file1.
My code is of:
Expected Output:
But unfortunately sed -i is not present in my AIX box, please shoot me an alternative. :)
Also if the IP address is not found in file2, that row should be left untouched in file1.
At the moment I am working in AIX box where sed -i is not available.
My requirement is as below
Two files file1 and file2. file1 contains the IP address, its count. file2 contains the Hostname and its corresponding IP address. I would like get the IP address replaced with the apt Hostname in file1.
Code:
# cat file1
192.168.20.8 => 1
192.168.20.24 => 2
192.168.20.6 => 2
192.168.20.7 => 3
192.168.20.9 => 3
192.168.20.25 => 4
192.168.20.26 => 4
192.168.20.23 => 6
Code:
# cat file2
192.168.20.6 ser70
192.168.20.7 ser71
192.168.20.8 ser72
192.168.20.9 ser73
192.168.20.23 ser80
192.168.20.24 ser81
192.168.20.25 ser82
192.168.20.26 ser83
Code:
for i in `awk '{print $1}' file1`
do
svr=$(grep $i file2 | awk '{print $2}')
sed -i "s/$i/$svr/" file1
done
Code:
# cat file1
ser72 => 1
ser81 => 2
ser70 => 2
ser71 => 3
ser73 => 3
ser82 => 4
ser83 => 4
ser80 => 6
Also if the IP address is not found in file2, that row should be left untouched in file1.