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!

looking for a number occurence in two files 1

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
hello,

thanks to feherke I can now split e.g. 211-219 into separate numbers... and now I'd like to present the next step.

I have two files:

File #1:
65-112
113-196
362-393
422-430
552-560

File #2:
89-112
113-168
244-332
361-360
377-462
488-511
582-698


After they are processed by feherke's iterate function and written to two new files, I need to find which number occures in both files.

Maybe it is feasible to find the numbers directly from the source files (the ones with 582-698, 488-511,...)?

thank you in advance,!!
 
Hi

With brute force is simple :
Code:
grep -xf /first/file /second/file
Code:
awk 'FNR==NR{n[$0]=1;next}$0 in n' /first/file /second/file
But as you mentioned, in case of big files wouldbe better to check the unexpanded intervals. How big could be those files ?

Feherke.
 
Hi

Not tested exhaustively, but works for you sample input. It produces output in the same from-to format :
Code:
awk -F '-' 'FNR==NR{f[NR]=$1;t[NR]=$2;next}{for(i=1;i in f;i++){l=f[i]>$1?f[i]:$1;u=t[i]<$2?t[i]:$2;if(l<=u)print l"-"u}}' /interval/file1 /interval/file2
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top