HELP with using a lookup table


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers HELP with using a lookup table
# 1  
Old 03-26-2007
HELP with using a lookup table

Using AIX 5.2, Bourne and Korn Shell.

I have two flat text files. One is a main file and one is a lookup table that contains a number of letter codes and membership numbers as follows:

316707965EGM01
315672908ANM92

Whenever one of these records from the lookup appears in the main file then it needs to be removed from the main file.

The problem is in the main file you will see 316707965 (membership number) in the first part of the file, like starting character 6 for 9 but EGM01 (letter code) later on in the file starting char 909 for 5 with other data in between.

I have tried egrep but there doesn't seem to be an and function.

Please can someone assist. Cheers

Last edited by Dolph; 03-26-2007 at 10:16 AM.. Reason: Alter message
# 2  
Old 03-26-2007
Can you show sample data from main file?
# 3  
Old 03-26-2007
The main data file would something like this. I have removed lots of fields as it would be to large.

00205679740100316707965 Mr T Test 20 Test Street Test Town TE2 7ST 2203200721032008February '08 MAR N00000000072.500043.500000000000072.50N N EGM01 0000010055
00205679740100315672908 Mr T Test2 40 Test Street Test Town TE2 7ST 2203200721032008February '08 MAR N00000000072.500043.500000000000072.50N N ANM92 0000010055

The file is fixed width so the fields in question will always be in the same place.

Thanks
# 4  
Old 03-26-2007
Code:
sed "s/^\(.\{9\}\)/\1.*/" lookup_file > tmp
grep -f tmp main_file

# 5  
Old 03-27-2007
anbu23

Thanks for that, works like a dream.
Could you please explain how the sed command is working and how the *. effects the grep command if you have time.

Many thanks for your help with this.

Dolph
# 6  
Old 03-27-2007
Here is another one which you can try....
"lookup" is the lookup file and "master" is the master data."updated_master" is the file which contains the updated data.

Code:
awk 'BEGIN {i=1; while((getline line <"lookup")>0) arr[i++]=line;  } { for(j=1;j<i;j++) {  if (match($0,substr(arr[j],1,9)) &&  match($0,substr(arr[j],10,5))) next; }  print $0; } ' master >updated_master

# 7  
Old 03-27-2007
Code:
$ echo 316707965EGM01 | sed "s/^\(.\{9\}\)/\1.*/"
316707965.*EGM01

tmp file contains above patterns.

. matches any single character
* Match any number (or none) of the single character that immediately precedes it
.* match any number of any character

Code:
grep -f tmp main_file

-f tmp The regular expression list is taken from the pattern_file tmp
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Getting Rid of Annoying Bootstrap Table Borders and Wayward Table Lines

Bootstrap is great; but we have had some issues with Bootstrapped <tables> (and legacy <fieldset> elements) showing annoying, wayward lines. I solved that problem today with this simple jQuery in the footer: <script> $(function(){ $('tr, td, fieldset,... (0 Replies)
Discussion started by: Neo
0 Replies

2. Shell Programming and Scripting

Korn shell - lookup table

Hi All I need to pass country code into a pipe delimited file for lookup. It will search country code (column 3) in the file, if the country code matched, it will return value from other columns. Here is my mapping file. #CountryName|CountryRegion|CountryCode-3|CountryCode-2... (5 Replies)
Discussion started by: lafrance
5 Replies

3. Shell Programming and Scripting

Filtering duplicates based on lookup table and rules

please help solving the following. I have access to redhat linux cluster having 32gigs of ram. I have duplicate ids for variable names, in the file 1,2 are duplicates;3,4 and 5 are duplicates;6 and 7 are duplicates. My objective is to use only the first occurrence of these duplicates. Lookup... (4 Replies)
Discussion started by: ritakadm
4 Replies

4. Shell Programming and Scripting

Build a table from a list by comparing existing table entries

I am new to this shell scripting.... I have a file which contains list of users. This files get updated when new user comes into the system. I want to create script which will give a table containing unique list of users. When I say unique, it means script should match table while parsing... (3 Replies)
Discussion started by: dchavan1901
3 Replies

5. UNIX for Dummies Questions & Answers

string replacement using a lookup table

Dear all thanks for helping in advance.. Know this should be fairly simple but I failed in searching for an answer. I have a file (replacement table) containing two columns, e.g.: ACICJ ACIDIPHILIUM ACIF2 ACIDITHIOBACILLUS ACIF5 ACIDITHIOBACILLUS ACIC5 ACIDOBACTERIUM ACIC1 ACIDOTHERMUS... (10 Replies)
Discussion started by: roussine
10 Replies

6. Shell Programming and Scripting

Sed variable from lookup table

I have a file with the following format --TABLEA_START-- field1=data1;field2=data2;field3=data3 --TABLEA_END-- --TABLEB_START-- field1=data1;field2=data2;field3=data3 --TABLEB_END-- --TABLEA_START-- field1=data1;field2=data2;field3=data3 ... (0 Replies)
Discussion started by: milo7
0 Replies

7. Programming

64-bit CRC Transition To Bytewise Lookup-Table

Good Evening, I started working on the 17x17 4-colouring challenge, and I ran into a bit of an I/O snag. It was an enormous headache to detect the differences in very similar 289-char strings. Eventually, it made more sense to associate a CRC-Digest with each colouring. After learning... (0 Replies)
Discussion started by: HeavyJ
0 Replies

8. Shell Programming and Scripting

Search, replace string in file1 with string from (lookup table) file2?

Hello: I have another question. Please consider the following two sample, tab-delimited files: File_1: Abf1 YKL112w Abf1 YAL054c Abf1 YGL234w Ace2 YKL150w Ace2 YNL328c Cup9 YDR441c Cup9 YDR442w Cup9 YEL040w ... File 2: ... ABF1 YKL112W ACE2 YLR131C (9 Replies)
Discussion started by: gstuart
9 Replies

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

10. Shell Programming and Scripting

lookup table in perl??

hi, i am very much new in perl and have this very basic question in the same:( the requirement is as below: i have an input file (txt file) in which i have fields invoice number and customer number. Now i have to take input this combination of invoice n customer number and check in a... (2 Replies)
Discussion started by: Bhups
2 Replies
Login or Register to Ask a Question