Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Alternate for sed -i in AIX

$
0
0
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.

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

My code is of:
Code:

for i in `awk '{print $1}' file1`
        do
        svr=$(grep $i file2 | awk '{print $2}')
        sed -i "s/$i/$svr/" file1
done

Expected Output:
Code:

# cat file1
ser72    => 1
ser81  => 2
ser70    => 2
ser71    => 3
ser73    => 3
ser82  => 4
ser83  => 4
ser80  => 6

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.

Viewing all articles
Browse latest Browse all 16232

Trending Articles