Sponsored Content
Top Forums Shell Programming and Scripting merging two files where countries are repeated Post 302489061 by durden_tyler on Wednesday 19th of January 2011 11:12:51 AM
Old 01-19-2011
Quote:
Originally Posted by vakharia Mahesh
... but it is not working , only the 1st instance is shown and not all the COUNTRIES names are mentioned. ... i.e. The output shows as :
OUTPUT FILE
=============
Abc , 1234 , London ,UK
Def , 2456 , Paris , France
Efg , 3456 , Newyork , USA
Fgh , 1324 , Tokyo , Japan
Hjk , 5829 , California ?
Lmn , 7823 , Chicago ?
Klm , 6472 , Munich , Germany
Jkm , 8231 , Frankfurt ?
Acl , 3241 , Hiroshima ?
Jmp , 2385 , Detroit ?
Lqm , 4613 , Kansas ?

That is the 1st instance of country will be displayed or joined and not in subsequent events ??

...
It is not working because your data doesn't match.

Brownie points for you if you could find the mismatch in each case yourself.

Code:
$
$ # display the contents of file2
$
$ cat file2
USA , Newyork
USA , California
USA , Sanfransisco
USA , Detroit
USA , Chicago
USA , Kansas
USA , St.Louise
USA , Florida
UK , London
FRANCE , Paris
FRANCE , Marsellie.
INDIA , NewDelhi
INDIA , Mumbai
INDIA , Calcutta
INDIA , Chennai
INDIA , Bangalore
JAPAN , Tokyo
JAPAN , Nagasaki
JAPAN , Hirosima
CANADA , Ottawa
CANADA , Montreal
CANADA , Vancuvor
ARGENTINA , Buenos Aires
BRAZIL , Brassila
BRAZIL , Sao Paulo
ITALY , Rome
NORVEY , Oslo
SPAIN , Madrid
GERMANY , Frankfurt
GERMANY , Munich,
USSR , Moscow
USSR , Laningrad
USSR , Vladvostok
$
$ # display the contents of file1
$
$ cat file1
Abc : 1234 : London
Def : 2456 : Paris
Efg :1456 : Newyork
Fgh : 1324 : Tokyo
Hjk  : 5829 : California
Lmn : 7823 : Chicao
Klm : 6472 : Munich
Jkm : 8231 : Franfurt
Acl : 3241 : Hiroshima
Jmp : 2385 : Detroit
Lqm : 4613 : Kansas
$
$ # run a Perl one-liner joining city to country
$
$ perl -lne 'if ($ARGV eq "file2"){/^(\w+)\s*,\s*(\w+)$/; $x{$2}=$1} else {/^.*:\s*(\w+)$/; $_="$_ , $x{$1}"; s/:/,/g; print}' file2 file1
Abc , 1234 , London , UK
Def , 2456 , Paris , FRANCE
Efg ,1456 , Newyork , USA
Fgh , 1324 , Tokyo , JAPAN
Hjk  , 5829 , California  ,
Lmn , 7823 , Chicao ,
Klm , 6472 , Munich ,
Jkm , 8231 , Franfurt ,
Acl , 3241 , Hiroshima ,
Jmp , 2385 , Detroit , USA
Lqm , 4613 , Kansas , USA
$
$

tyler_durden
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 01:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy