How to combine 2 texts file and create another file from it?

Hi all,

I've the following hostnames & ip addresses saved in host_ip.txt

Based on this list, I need to create the following script.

where by HH is a hostname
and XXXX is an ip address

So the final output would be something like this.

Currently, I'm doing it manually, replace, copy and paste. Since there are hundreds of Hosts & IP Addresses, I really appreciate if someone could help me to automate this task using a script or any methods. Thanks in advance

awk '{
      print "create host_plain " $1;
      print "modify network_objects "$1" ipaddr " $2;
      print "update network_objects "$1;
      print " ";
}' host_ip.txt
1 Like

Thanks, it works like a charm. One more question. How to save this output, let say into output.txt?

Nevermind, found the answer :slight_smile:

awk '{
      print "create host_plain " $1;
      print "modify network_objects "$1" ipaddr " $2;
      print "update network_objects "$1;
      print " ";
}' host_ip.txt > output.txt
1 Like