| | |
Comparing 2 files and then apending matches
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Solved Threads: 0
Hi ,
I have a work project on at the moment and am struggling to find the answer!!
I have 2 files. 1 file contains a huge list of stuff in the following format
123456789 HOSTNAME 0 415 VLR_HPLMN
I then have a file which has an entry in it in the following format
HOSTNAME~123456789~123456789 ANOTHERHOSTNAME 0 415 VLR_HPLMN SIGTRAN
What I need to do , is look down the 2 files, and Match the number from the 1st file, to the number in the 2nd file. If it finds a match I then need to append the differences on the end of the line . i.e in this instance i need to add SIGTRAN on the end of the entry in file 1.
Can anyone help??????
I have a work project on at the moment and am struggling to find the answer!!
I have 2 files. 1 file contains a huge list of stuff in the following format
123456789 HOSTNAME 0 415 VLR_HPLMN
I then have a file which has an entry in it in the following format
HOSTNAME~123456789~123456789 ANOTHERHOSTNAME 0 415 VLR_HPLMN SIGTRAN
What I need to do , is look down the 2 files, and Match the number from the 1st file, to the number in the 2nd file. If it finds a match I then need to append the differences on the end of the line . i.e in this instance i need to add SIGTRAN on the end of the entry in file 1.
Can anyone help??????
If you want the records that don't match also:
Without them:
Use nawk or /usr/xpg4/bin/awk on Solaris.
Shell Scripting Syntax (Toggle Plain Text)
awk 'NR==FNR{x[$2]=$NF;next} $1 in x?$0=$0" "x[$1]:1' FS="[~ ]" file2 file1
Without them:
Shell Scripting Syntax (Toggle Plain Text)
awk 'NR==FNR{x[$2]=$NF;next} $1 in x?$0=$0" "x[$1]:0' FS="[~ ]" file2 file1
Use nawk or /usr/xpg4/bin/awk on Solaris.
Last edited by radoulov; Oct 2nd, 2007 at 9:24 am.
![]() |
Similar Threads
- Is this software any good? (Viruses, Spyware and other Nasties)
- Comparing two files and output values that match (Shell Scripting)
- Comparing two files... (Shell Scripting)
- Opinions? javascript/php/etc and programming standards (JavaScript / DHTML / AJAX)
- help with c++ vectors (C++)
- Compare 2 Lists of Words (MySQL)
- Trojan virus - need help please. (Viruses, Spyware and other Nasties)
- Trojan.Bookmarker.gen/about:blank (Viruses, Spyware and other Nasties)
Other Threads in the Shell Scripting Forum
- Previous Thread: Shell Script to CLean up Files
- Next Thread: FireWall Back ups with Expect
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





