merging two files where countries are repeated


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting merging two files where countries are repeated
# 8  
Old 01-20-2011
To thank in this forum is, click the Thanks Thumb.

a[$3] is used to build an array a in awk.
This User Gave Thanks to rdcwayx For This Post:
# 9  
Old 01-20-2011
Power

Hi rdcwayx
Sorry I did not click the Thumb impression ,now corrected and I appreciate your help but
the moot question was the a[3] will have the value of 3rd field of File1 or file2 ?
secondly What I wanted to know is
(1) should we use which file 1st and why
(2) how fields i.e. the common on which we want to join or likewise and use them in array ?
(3) In case of more instancies in my case , loooping is necessary ?
Can you guide me rdcwayx please
Thanks in advance,
# 10  
Old 01-21-2011
Code:
awk -F"[:,]" '
NR==FNR{a[$2]=$1;next;}   # (1) It only builds array a for file2 (that's the first file in awk command) , NR==FNR is used to control it. 
a[$3]  # (2) then check if we have the same value in arrary a a[$3]'s value is not 0 or null. 
{ print $1,$2,$3,a[$3]}' file2  # First file
 OFS="," file1  # second file

For the third question, I am not really understand. Do you mean you need update more files with country and city, then just add the file name one by one.

awk .....  file2 OFS="," file1 file3 file4 file5

This User Gave Thanks to rdcwayx For This Post:
# 11  
Old 01-21-2011
So kind of you rdcwayx ,wish you nice weekend .
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk for matching fields between files with repeated records

Hello all, I am having trouble with what should be an easy task, but seem to be missing something fundamental. I have two files, with File 1 consisting of a single field of many thousands of records. I also have File 2 with two fields and many thousands of records. My goal is that when $1 of... (2 Replies)
Discussion started by: jvoot
2 Replies

2. UNIX for Beginners Questions & Answers

Matching fields between two files, repeated records

In two previous posts (here) and (here), I received help from forum members comparing multiple fields across two files and selectively printing portions of each as output based upon would-be matches using awk. I had been fairly comfortable populating awk arrays with fields and using awk's special... (3 Replies)
Discussion started by: jvoot
3 Replies

3. Shell Programming and Scripting

Compare two files with repeated lines

Hi all, I've been trying to write a script to compare two files. This is what I want: file 1: a 1 2 b 5 9 c 4 7 file 2: a a c a b Output: a 1 2 a 1 2 (2 Replies)
Discussion started by: ernesto561
2 Replies

4. What is on Your Mind?

UNIX field scope in European countries

Hi, I have been working in India since past 13 years and as per Indian IT culture, there will be saturation in Salary which barely matches with rising living costs in India. I am thinking to move/work in some other country for few years at least which help me financially plus technically. As of... (3 Replies)
Discussion started by: nightup2222
3 Replies

5. Shell Programming and Scripting

Find repeated word and take sum of the second field to it ,for all the repeated words in awk

Hi below is the input file, i need to find repeated words and sum up the values of it which is second field from the repeated work.Im trying but getting no where close to it.Kindly give me a hint on how to go about it Input fruits,apple,20,fruits,mango,20,veg,carrot,12,veg,raddish,30... (11 Replies)
Discussion started by: 100bees
11 Replies

6. Forum Support Area for Unregistered Users & Account Problems

Trouble Registering? Countries or Regions Abusing Forums

The forums have been seeing a sharp increase in spam bots, forum robots, and malicious registrations from certain countries. If you have been directed to this thread due to a "No Permission Error" when trying to register please post in this thread and request permission to register, including... (1 Reply)
Discussion started by: Neo
1 Replies

7. Shell Programming and Scripting

[Solved] Parsing countries file

Hi All I would like to take contries for this file http://www.textfixer.com/resources/dropdowns/country-dropdown-iso-html.txt and save it in another file with the following structure . Afghanistan, Åland Islands , Albania, Algeria, American Samoa Can anyone help me to do this ? (3 Replies)
Discussion started by: molwiko
3 Replies

8. Solaris

Huge (repeated Entry) text files

Somebody HELP! I have a huge log file (TEXT) 76298035 bytes. It's a logfile of IMEIs and IMSIS that I get from my EIR node. Here is how the contents of the file look like: 000000, 1 33016382000913 652020100423994 1 33016382002353 652020100430743 1 33017035101003 652020100441736... (4 Replies)
Discussion started by: axl
4 Replies
Login or Register to Ask a Question