Swapping IP Addresses In A File With Those From Another File
Hello,
I'm looking for a way to change the IP addresses in a large host file with those of matching hostnames in another file.
For example, I have a file with
file1 contains lines like:
and file2 has:
In reality, file1 has about 800 lines, and file2 has about 100 lines, and I need to change the IP address in file1 with those new ones in file2 for the hosts that match.
I'm looking at using just sh or ksh with sed/awk, but can't seem to get the logic straight. It would be easy enuf if it were just changing one entry with sed and redirecting to new a file, but when it comes to changing 100+ entries in a file, not sure how to approach it. This is on Solaris.
Any and all help appreciated.
Thanks.
Moderator's Comments:
Please use code tags when posting data and code samples!
Last edited by vgersh99; 01-20-2011 at 02:25 PM..
Reason: code tags, please!
Shell script logic
Hi
I have 2 input files like with file 1 content as (file1)
"BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt
File 2 contents as fle(2)
"BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt
I want to get... (22 Replies)
Hi Friends ,
I have file1.txt
1|b|46|123|47673|348738
2|c|63|124|7346|4783
3|y|45|125|5555|78789
output should swap the 4th field to the first field.
output
123|1|b|46|47673|348738
124|2|c|63|7346|4783
125|3|y|45|5555|78789 (3 Replies)
Hi,
I'd like to swap the columns 1 and 2 of a space-delimited text file but only for the first 1000 rows. How do I go about doing that? Thanks! (1 Reply)
So I'm new to this sed command and I am trying to create a script that replaces ip addresses when I name a file but can't tweak it to work.
Here is what it looks like:
#!/bin/bash
#
file=$1
#
sed -e 's/-CPUaddr 10.30.10.166/-CPUaddr 10.30.10.151/g' -i "$file"
sed -e 's/-CPUaddr... (10 Replies)
I have an xml file with IP addresses all over the show. I want to print only the IP addresses and cut off any text before or after the IP address.
Example:
Note: The IP addresses (x.x.x.x) do not consistently appear in the xml file as per the pattern below. Sometimes there are text before... (8 Replies)
All,
I have a flat file which contains an email address in every line. I am trying to find a way to extract all the email addresses delimited by comma (,). Can you please show me a way, it will be very helpful, thanks. (3 Replies)
Hi all
i need to create a script that pings every server in my range (0-254) adn then returns the values to a file? can anyone please help. i am working in the tcsh ( and yes i know how to ping ) but i dont know how to ping them all in one script without copying and pasting a 254 times?
... (1 Reply)
Hi,
How to swap two strings in a file ?
Ex: "ABC" to be swapped with "XYZ"
"ABC" and "XYZ" donot occur in a same line .
String has ""
Regards
Tej (8 Replies)
Hi
I have afile with 15fields,say f1,f2....f15 delimited on comma. How can i swap the f1,f15 fields using unix shell commands or any script?
Thanks (3 Replies)
Write a quick shell snippet to find all of the IPV4 IP addresses
in any and all of the files under /var/lib/output/*, ignoring
whatever else may be in those files. Perform a reverse lookup on
each, and format the output neatly, like "IP=192.168.0.1,
... (0 Replies)