Sponsored Content
Full Discussion: awk record matching
Top Forums Shell Programming and Scripting awk record matching Post 302992438 by SkySmart on Friday 24th of February 2017 05:55:40 PM
Old 02-24-2017
awk record matching

ok. so i have a list of country names which have been abbreviated. we'll call this list A

i have another list that which contains the what country each abbreviated name means. we'll call this list B.


so example of the content of list B:

Code:
#delimited by tabs
#ABBR COUNTRY     COUNTRY ABBR
so      Somalia ST. KITTS AND NEVIS     KN
sr      Suriname        ST. LUCIA       LC
st      Sao Tome And Principe   ST. PIERRE AND MIQUELON PM
su      Soviet Union    ST. VINCENT & THE GRENADINES    VC
sv      El Salvador     SUDAN   SD
sy      Syrian Arab Republic    SURINAME        SR
sz      Swaziland       SVALBARD AND JAN MAYEN  SJ
tc      Turks And Caicos Islands        SWAZILAND       SZ
td      Chad    SWEDEN  SE
tf      French Southern Territories     SWITZERLAND     CH
tg      Togo    SYRIAN ARAB REPUBLIC    SY
th      Thailand        TAIWAN  TW
tj      Tajikistan      TAJIKISTAN      TJ
tk      Tokelau TANZANIA, UNITED REPUBLIC OF    TZ
ti      East Timor (new code)   THAILAND        TH
tm      Turkmenistan    TOGO    TG
tn      Tunisia TOKELAU TK
to      Tonga   TONGA   TO
tp      East Timor (old code)   TRINIDAD AND TOBAGO     TT
tr      Turkey  TUNISIA TN
tt      Trinidad And Tobago     TURKEY  TR
tv      Tuvalu  TURKMENISTAN    TM
tw      Taiwan  TURKS AND CAICOS ISLANDS        TC
tz      Tanzania, United Republic Of    TUVALU  TV
ua      Ukraine UGANDA  UG
ug      Uganda  UKRAINE UA
uk      United Kingdom  UNITED A

how can i get awk to tell me the full country name if i supply the country's abbreviation? also note, some abbreviated countries (left column) are in lowercase, and others are in CAPs (right column).

The above list of countries is stored in a variable. so i intend to do something like this:

Code:
#!/bin/sh
SuppName=${1}
echo "${ListBContent}" | awk -v SupName="${SupName}" '(($1 ~ SupName) || ($3 ~ SupName)) {print $0}'

My question is, is there a more efficient, better way to do this? i
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk: record has too many fields

Hi, I'm trying this command - but get this error. Do you guys have any workaround for this? cat tf|sed 's/{//g'|sed 's/,//g'|awk '{for (i=1;i<=NF;i++) {if ($i == "OPTIME") {k = i + 2; print $i,$k}}}' awk: record `2005 Jul 28 17:35:29...' has too many fields record number 15 This is how... (3 Replies)
Discussion started by: chaandana
3 Replies

2. Shell Programming and Scripting

AWK - if last line/record do something

Hello: I am trying to perform a certain action if the current record is the last line of the input file. But I am unable to figure out how to determine the last line of a file in awk. I need to do something like this: awk '{ if (lastline == NR) Do Something}' myfile.txt I have tried the... (3 Replies)
Discussion started by: PacificWonder
3 Replies

3. Shell Programming and Scripting

select a record from one file matching from second file using awk

I need help :) I have two input files and I'd like to generate a report based on the two. filea: hostname,account1,password ,account2,password hostname,account1,password hostname,account1,password ,account1,password ,account2,password repeating hostnames are blank fileb: hosta... (7 Replies)
Discussion started by: synmag
7 Replies

4. UNIX for Dummies Questions & Answers

Record splitting with AWK

Hi all ! I need your help as quick as possible. My input file like this: bạc těnh ( 薄情) 1 . 薄情な.2. 夫婦或いは男女の不貞を指す。 bách (百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ)・ 3.圧迫する.4.差し迫った, My propose is take the value in the firt bracket. I used the command like : ...if (index(... (6 Replies)
Discussion started by: maixu134
6 Replies

5. Shell Programming and Scripting

selecting record by matching in two columns values

Hi Guys ! i want to search a record in file by matching two values in a record in two different columns suppose i have 3 columns and i want to select all those values from col1 for which in col3 has a specific value e.g select all "john" from column1 where column 3 has a value of "20" ... (9 Replies)
Discussion started by: ourned
9 Replies

6. Shell Programming and Scripting

awk: matching and not matching

Hello all, simple matching and if not match problem that i can't figure out. file1 hostname: 30 10 * * * /home/toto/start PROD instance_name1 -p 00 9 * * * /home/toto/start PROD instance_name2 -p 15 8 * * * /home/toto/start PROD instance_name3 -p hostname2: 00 8 * * *... (5 Replies)
Discussion started by: maverick72
5 Replies

7. UNIX for Dummies Questions & Answers

awk: record too long

Hi All , I am getting record too long for the below command . nawk -F\" '{a=a" "$2} END{for(i in a) print i,a }' test|sort|awk '{for(i=1;i<=NF;i++) t=t"\t"$i;if(NF>max)max=NF} END{for(i=1;i<=max;i++)print t }' File test has 850 records ... Please help.. (2 Replies)
Discussion started by: saj
2 Replies

8. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

9. Shell Programming and Scripting

awk print matching records and occurences of each record

Hi all , I have two files : dblp.xml with dblp records and itu1.txt with faculty members records. I need to find out how many dblp records are related to the faculty members. More specific: I need to find out which names from itu1.txt are a match in dblp. xml file , print them and show how many... (4 Replies)
Discussion started by: iori
4 Replies

10. Shell Programming and Scripting

awk to combine all matching dates and remove non-matching

Using the awk below I am able to combine all the matching dates in $1, but I can not seem to remove the non-matching from the file. Thank you :). file 20161109104500.0+0000,x,5631 20161109104500.0+0000,y,2 20161109104500.0+0000,z,2 20161109104500.0+0000,a,4117... (3 Replies)
Discussion started by: cmccabe
3 Replies
GEOIP_TIME_ZONE_BY_COUNTRY_AND_REGION(3)				 1				  GEOIP_TIME_ZONE_BY_COUNTRY_AND_REGION(3)

geoip_time_zone_by_country_and_region - Returns the time zone for some country and region code combo

SYNOPSIS
string geoip_time_zone_by_country_and_region (string $country_code, [string $region_code]) DESCRIPTION
The geoip_time_zone_by_country_and_region(3) function will return the time zone corresponding to a country and region code combo. In the United States, the region code corresponds to the two-letter abbreviation of each state. In Canada, the region code corresponds to the two-letter province or territory code as attributed by Canada Post. For the rest of the world, GeoIP uses FIPS 10-4 codes to represent regions. You can check http://www.maxmind.com/app/fips10_4 for a detailed list of FIPS 10-4 codes. This function is always available if using GeoIP Library version 1.4.1 or newer. The data is taken directly from the GeoIP Library and not from any database. PARAMETERS
o $country_code - The two-letter country code (see geoip_country_code_by_name(3)) o $region_code - The two-letter (or digit) region code (see geoip_region_by_name(3)) RETURN VALUES
Returns the time zone on success, or FALSE if the country and region code combo cannot be found. EXAMPLES
Example #1 A geoip_time_zone_by_country_and_region(3) example using region code for US/Canada This will print the time zone for country CA (Canada), region QC (Quebec). <?php $timezone = geoip_time_zone_by_country_and_region('CA', 'QC'); if ($timezone) { echo 'Time zone for CA/QC is: ' . $timezone; } ?> The above example will output: Time zone for CA/QC is: America/Montreal Example #2 A geoip_time_zone_by_country_and_region(3) example using FIPS codes This will print the time zone for country JP (Japan), region 01 (Aichi). <?php $timezone = geoip_time_zone_by_country_and_region('JP', '01'); if ($timezone) { echo 'Time zone for JP/01 is: ' . $timezone; } ?> The above example will output: Time zone for JP/01 is: Asia/Tokyo PHP Documentation Group GEOIP_TIME_ZONE_BY_COUNTRY_AND_REGION(3)
All times are GMT -4. The time now is 12:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy