Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check between two files

Status
Not open for further replies.

majesty250

Technical User
Jun 20, 2002
6
IT
Could someone help me to figure it out my problem?
My fileA has 250K rows whit 2 fields like this
1234567 aabc
9873452 ac3f
...
My fileB has 1.2M rows with 3 or more fields like this:
I 5346282 ab4d 20020701
I 6759902 hhf3 20020901
...
I have to search the field1 of fileA in fileB and put in an external file: fields 1,2,4 of fileB and filed2 of fileA.
I know that using while cycle could be easier but it needs too much time. I'm looking for a shorter method.
Thanks and regards
 
You need to find all matching first columns in the two files, and when these match you need to write fld2 from the first and flds 1 , 2 and 4 from the second , is this right?


You could try this kind of approach.

awk ' BEGIN {
while ((getline array[a++] < file1) > 0) {
}
close(file1)
}
{

for (xx in array) {
cnt = split(array[xx],local,&quot; &quot;]
if (cnt) {
if ($1 == local[1]) {
print arr[2], $1, $2, $4 >> newfile
}
}
}
}

 
marsd,

thanks for working on my stuff.
I decided to move to another direction. Your suggestion was too heavy for my machine, so as first step I grep out all records I need from the bigger file, than I gone ahead with awk having two files with same number of records.
Thanks for your effort.

majesty250
 
Yes, that's much simpler than the huge number of
times you will iterate over those entries otherwise.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top