Sun 0S script needed, input file crossmatch

columcusack
columcusack used Ask the Experts™
on
Hi There Experts.

Ok, here is my query

I have two files.  Input file one will be a list of numbers that will cross-reference input file two. Basically file two has the same numbers but with more data.

I need to feed in input file one (just one field of numbers) and cross check against file two.....but also extract two additional fields from file two and put all into an output file 3


for example..
 
Input file one as follows
 
851715666
858765673
 
Input file 2 as follows
 
851715666,851715666,0,0,,0,1,1,0,0,0,0,0,0,1,1,1,11,11,,0,1,27/08/2011,27/08/2011,,24/02/2012,0,0,24/03/2012,0,0,,0,1,0,0,0,0,0
 
858765673,858765673,0,0,,1,1,1,0,0,0,0,0,0,1,1,1,14,14,,19.641833,1,11/07/2010,11/06/2010,,11/09/2010,0,0,10/09/2010,0,0,,0,1,0,0,0,0,512
 
Field 18 and 19 is what I need from this file with field one from my input file 1.  You can see that field one and field two from input file two are the same as input file one
 
My result should look like 
 
851715666,11,11
858765673,14,14
 
I'm under severe pressure to get these results and would appreciate if you can help me.  I have complete faith in you guys....this will be run on a SUN OS

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try this:
 

grep -f file1 file2 |cut -d',' -f1,18,19 >file3

Open in new window

Author

Commented:
It does not seem to  like the -f option?  its SunOS

# grep -f file1.TXT file2.TXT | cut -d',' -f1,18,19 > file3.TXT
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .
# uname -a
SunOS dcr1a 5.10 Generic_127111-09 sun4u sparc SUNW,Sun-Fire-V240
#

Author

Commented:
Thanks
Top Expert 2007

Commented:
Here's a generic solution that will work on any Unix/Linux system
#!/bin/sh
for num in `cat file1`
do
  grep $num file2 | cut -d, -f1,18,19 >>file3.TXT
done

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial