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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare files to filter same keywords

Status
Not open for further replies.

ruebensau

Programmer
Dec 14, 2005
3
DE
I have two files. Each field in files is seperated with comma.

The first files has 7 fields and the second one only 2.

I want to take the second field from the first file and search the content of this field in the second file.

If found, the script should copy the line of the first file and the found line of the second file into one line in a new file.

Example:

file1:
19,768,ROHRLEITUNGEN-IM-7M-STREIFEN-DER-BE,####,####,####,25/08/2003
19,798,FUNDAMENTE-ZUM-CHLORKESSEL-LAGER-4,####,####,####,05/03/1997
...

file2:
r1900898.dgn,\\ta-cad\ac\r1900898.dgn
r1900768.dgn,\\ta-cad\ac\r1900768.dgn
J+G-Farbe.ctb,\\ta-cad\ACAD_Umgebung\Plot Styles\J+G-Farbe.ctb
r1900798.dgn,\\ta-cad\ac\r1900798.dgn
r1923908.dgn,\\ta-cad\ac\r1923908.dgn
....

The result shuld be like this:
19,768,ROHRLEITUNGEN-IM-7M-STREIFEN-DER-BE,####,####,####,25/08/2003,r1900768.dgn,\\ta-cad\ac\r1900768.dgn

19,798,FUNDAMENTE-ZUM-CHLORKESSEL-LAGER-4,####,####,####,05/03/1997,r1900798.dgn,\\ta-cad\ac\r1900798.dgn

greets
rübensau
 
You may try something like this:
awk -F, '
NR==FNR{a[$2]=$0;next}
{for(i in a)if($1~i){print a","$0;next}}
' file1 file2


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top