Sponsored Content
Full Discussion: AWK lookup not finding match
Top Forums UNIX for Dummies Questions & Answers AWK lookup not finding match Post 302466945 by gio001 on Wednesday 27th of October 2010 07:01:49 PM
Old 10-27-2010
AWK lookup not finding match

Hello everyone,
I have been struggling with the following situation, I think I am doing something wrong, can anyone help?
I have 2 comma separated files, the first is a look-up table that will supply the phone number based on the customer id, the second is a file containing customers and their id.
I would like to generate a file with customer name an phone number for each customer.
No matter what I try I do not seem to find proper matches. The code I have always runs into the 'not matched' section and generated the 'Error' string as printout for all of my incoming records.
When I will manage to see the matching occur then I will introduce the proper PRINT to gather all the data andl place that onto the output, for now I am just trying to see if I am actually able to match.
I also included the for loop at the end just to see I had populated the array properly .... everything to my eyes seems ok, yet I cannot get the matches to occur. Additionally can I also avoid the displaying of all the lines getting processed to go to the screen, I do not see which section of the code is doing that?

Hope someone can help.
Thanks in advance!

File uno contains:
Code:
000000030292,4121234567
000000031064,4121234444
000000031125,4122223474

File due contains:
Code:
000000030292,NAME1, LASTNAME1          ,OP      ,TESTING1     ,OP           ,FRI,10/29/2010,1100 ,FT,ENG
000000031064,NAME2, LASTNAME2          ,OP      ,TESTING2     ,OP           ,FRI,10/29/2010,1600 ,FT,ENG
000000031125,NAME3, LASTNAME3          ,OP      ,TESTING3     ,OP           ,FRI,10/29/2010,1500 ,FT,ENG

Code:
awk 'FS=","
     FILENAME=="uno" {cd1[$1]=$2}
     FILENAME=="due" {
     if ( $1 in cd1)
      	{
      	    print $0" Found" > "outtel"
  
       	}
       	else
       	{
     	     print $1"Error" > "outtel"
  
       	}
} END {for (var in cd1){print var"---"cd1[var]"-" >"outtel"}}' due uno

This is the output I get in outtel:
Code:
000000030292Error
000000031064Error
000000031125Error
000000031125---4122223474-
000000031064---4121234444-
000000030292---4121234567-

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Clueless about how to lookup and reverse lookup IP addresses under a file!!.pls help

Write a quick shell snippet to find all of the IPV4 IP addresses in any and all of the files under /var/lib/output/*, ignoring whatever else may be in those files. Perform a reverse lookup on each, and format the output neatly, like "IP=192.168.0.1, ... (0 Replies)
Discussion started by: choco4202002
0 Replies

2. Shell Programming and Scripting

Finding exact match string

Hi All, I'm writing unix script, it should find exact matching in search string. Looks simple but when i started i'm stuck to find the exact match character string. The unix script reads the records from DB Table. The table will have values something likes these Feed : A Feed File name :... (3 Replies)
Discussion started by: luckybalaji
3 Replies

3. UNIX for Dummies Questions & Answers

finding all files that do not match a certain pattern

I hope I'm asking this the right way -- I've been sending out a lot of resumes and some of them I saw on Craigslist -- so I named the file as 'Craigslist -- (filename)'. Well I noticed that at least one of the files was misspelled as 'Craigslit.' I want to eventually try to write a shell... (5 Replies)
Discussion started by: Straitsfan
5 Replies

4. Shell Programming and Scripting

Question on awk for finding the column number using a match word

Hi Guys, Please help me out in my situation of writing a shell script Exampl:I have a output like asnapply 1 2 3 apply_server=1 apply_schema=ASN asnapply 1 2 3 apply_server=2 apply_schema=ASN Now i need output like asnacmd applysever=1 applyschema=ASN stop asnacmd applysever=2... (16 Replies)
Discussion started by: mallak
16 Replies

5. UNIX for Dummies Questions & Answers

finding the nth match

I have a file that has information for a person....each person gets 3 or more lines to describe them. I was hoping to match person 1, then person 2.....BUT I do not know how to tell grep I only want the first (2nd, 3rd or nth) match. The alternative is doing line by line logic, which is fine... (8 Replies)
Discussion started by: countryStyle
8 Replies

6. Shell Programming and Scripting

[Solved] Lookup a file and match the contents

Hi, I appreciate all who have been very helpful to me in providing valuable suggestions and replies. I want to write a script to look up a file and match the contents. Let me go through the scenario. Lets say i have two files Content file: abc, bcd, adh|bcdf|adh|wed bcf, cdf,... (2 Replies)
Discussion started by: forums123456
2 Replies

7. UNIX for Dummies Questions & Answers

Help with AWK - Compare a field in a file to lookup file and substitute if only a match

I have the below 2 files: 1) Third field from file1.txt should be compared to the first field of lookup.txt. 2) If match found then third field, file1.txt should be substituted with the second field from lookup.txt. 3)Else just print the line from file1.txt. File1.txt:... (4 Replies)
Discussion started by: venalla_shine
4 Replies

8. Shell Programming and Scripting

awk base lookup of best match strings

Hi, I'm new to scripting and unable to find out a way to perform the below task. Request help in finding out a way to accomplish this. File one consists of some numbers/string which i need to lookup against file 2 and fetch the best match results in output. If best match is not present in... (3 Replies)
Discussion started by: suraj016
3 Replies

9. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies
mlib_ImageLookUp_Inp(3MLIB)				    mediaLib Library Functions				       mlib_ImageLookUp_Inp(3MLIB)

NAME
mlib_ImageLookUp_Inp - table lookup, in place SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_ImageLookUp_Inp(mlib_image *srcdst, const void **table); DESCRIPTION
The mlib_ImageLookUp_Inp() function maps the source image to the destination image, in place, by using the user-specified lookup table. The following equation is used: srcdst[x][y][i] = table[i][srcdst[x][y][i]] PARAMETERS
The function takes the following arguments: srcdst Pointer to first source and destination image. table Pointer to lookup table. The data type of the lookup table is the same as the destination image. The number of entries in the lookup table is determined by the type of the input image. The format of the lookup table is: table[channel][index] The MLIB_BYTE type entries are indexed from 0 to 255. The MLIB_SHORT type entries are indexed from -32768 to -1, then from 0 to 32767. The MLIB_USHORT type entries are indexed from 0 to 65535. The MLIB_INT type entries are indexed from -2147483648 to -1, and then from 0 to 2147483647. RETURN VALUES
The function returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_ImageLookUp(3MLIB), mlib_ImageLookUp2(3MLIB), mlib_ImageLookUpMask(3MLIB), attributes(5) SunOS 5.10 10 Nov 2004 mlib_ImageLookUp_Inp(3MLIB)
All times are GMT -4. The time now is 02:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy