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!

Array prob

Status
Not open for further replies.

olympiakos

Technical User
Jan 24, 2004
4
GR
Hello all,

I want to ask you if and how I can perform the following task using awk and arrays (even though they are single-dimensional).
I have 2 files of the format:

File1:

ET-123 WO
ET-135 WO
ET-158 SE

FILE2:

ET-123 WO 620

The example I give is typical but the volume of the files is much bigger.
My question is, how can I put the value 620 to file1 for every value of $1 that matches on both files?

I would appreciate any feedback.

Thanks
 
Provided your 2 files are sorted: man join

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
If not sorted, try

awk -f oly.awk file2 file1

#------ oly.awk ------
FNR==NR{a[$1]=$3;next}
{print $0,a[$1]}

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Thank you guys for your swift response.

The script CaKiWi you put on, it doesnt do the trick.

I post portion of these files.

FILE1
ET-653 SE-NH
ET-654 WO-EX
ET-655 WO-EX
ET-656 WO-EX
ET-657 WO-EX
ET-658 WO-EX
ET-659 WO-EX
ET-660 WO-EX
ET-661 WO-EX
ET-662 WO-EX
ET-663 WO-EX
ET-664 WO-EX
ET-665 WO-EX
ET-666 WO-EX
ET-667 SE-NH
ET-668 WO-EX
ET-669 SE-NH
ET-670 WO-EX


FILE2
27-20 WO-EX 620
627-21 WO-EX 620
627-22 WO-EX 620
627-23 WO-EX 620
627-24 WO-EX 620
627-25 WO-EX 620
659-3 WO-EX 620
659-4 WO-EX 620
659-5 WO-EX 620
659-6 WO-EX 620
659-7 WO-EX 620
659-8 WO-EX 620
659-9 WO-EX 620
659-10 WO-EX 620
659-11 WO-EX 620
659-12 WO-EX 620
659-13 WO-EX 620
659-14 WO-EX 620
659-15 WO-EX 620

I can get rid of the duplicate lines no prob.

I hope this clarifies my question.

 
What output do you want from these 2 files?

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Ooops I did......
File 2 doesnt start with what it should......
Thanks guys:)
 
What is the common stuff between the 2 files, the relation must be made on ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thank u PHV for your assistance.
The 2 files ARE(after some manipulation from my side) going to be: file2 is the subset of file1 meaning all file2 RECORDS are in file1 BUT WITHOUTH THE $3 column which is the value 620 in the example I gave you.

Once again thank you guys..:)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top