lookup in unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers lookup in unix
# 1  
Old 07-31-2008
lookup in unix

i am having one file which is of CSV format with two fields client_id and client_nbr.The sample data is lke below

ABC,1250
CDE,1520
EFG,1000
PQR,1800

The client nbr for these clients change frequently.So i want to create one lookup file every week for the changed client and run a script sothat in original CSV the client nbr will change.
Say for week1 the client nbr for two clients changed

ABC,1000
PQR,1500

This will be placed in a CSV file(lookup file)

After running the script the output in the original file should be


ABC,1000
CDE,1520
EFG,1000
PQR,1500

Please help me writing the script.
# 2  
Old 07-31-2008
- Script should not touch/move/edit original file.
- When you run script it should save original file and then work on copy of it and paste it back as original.
- Get the contents of original file using cat, strings command and compare with it current changes.(Use for loop)
- If there is a change then replace new value with old one otherwise do nothing.

- nilesh
# 3  
Old 07-31-2008
Code:
awk -F, -v OFS=, '
    # load array with changed client numbers
    NR==FNR { client_num[$1]=$2; next }
    # if this client has changed, print updated record
    $1 in client_num { print $1,client_num[$1]; next }
    # otherwise just print the current record
    1
' file_with_changes originalfile > newfile


Last edited by Annihilannic; 07-31-2008 at 03:04 AM.. Reason: forgot OFS
# 4  
Old 07-31-2008
Hi,

Since u are running the script every week , i think the below scritp might help u.

f1--The first column ie ABC etc
f2--The second column ie 1200 etc

cat file | cut -d ',' -f1 > file1 # This will take the first column in file1
cat file | cut -d ',' -f2 > file2 # This will take the second column in file2
paste -d, file1 file2 # This would paste first and second column with commas

Cheers!
Jegan
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array V-Lookup using UNIX bash

Hey everyone, I am trying to extract column values from a column in a tab-delimited text file and overlay them in a 2nd tab-delimited text file using a V-lookup type script in Unix bash. These are the 1st few rows of the 1st input file IN1: rsid chromosome position allele1 ... (10 Replies)
Discussion started by: Geneanalyst
10 Replies

2. Shell Programming and Scripting

Lookup field values in two fixed format file in UNIX - not working

I have 2 fixed length files input#1 & input#2. I want to match the rows based on the value in position 37-50 in both files (pos 37-50 will have same value in both files). If any matching record is found then cut the value against company code & Invoice number from input file #1 (position 99 until... (3 Replies)
Discussion started by: Lingaraju
3 Replies

3. Shell Programming and Scripting

Lookup name from another file

Hi All, I want to lookup name for an id in col2 input from another file and add the name to each line. Input 1 comp100001_c0_seq1 At1g31340 30.40 569 384 11 3 1673 313 834 7e-62 237 comp100003_c0_seq1 At1g35370_2 35.00 80 50 ... (7 Replies)
Discussion started by: gina.lizar
7 Replies

4. UNIX for Dummies Questions & Answers

Lookup in Unix

Hi, I have an input file which contain below records: a,1 b,2 c,3 a,10 b,34 i have a reference file which contains below records: a,AA b,BB c,CC My required output is : (3 Replies)
Discussion started by: pandeesh
3 Replies

5. UNIX for Dummies Questions & Answers

Checking for unix hosts that do not have reverse lookup

Hi there i am not sure how to explain my problem. i need to run a script to give me the results of all my unix hosts that do not have reverse lookup activated (for lack of a better word), i need to give this to out Server guys to add it part of the AD rules. So what i need is a script to... (0 Replies)
Discussion started by: brian112
0 Replies

6. Shell Programming and Scripting

lookup

I have a lookup file in unix say /data/lkp.dat (First line is header and space delimited) and the content is shown below. Another file which contains the job_name and rec_count lets say /data/data_file.dat(no header pipe delimited file). Now i want to do a lookup on job_name and my output should... (3 Replies)
Discussion started by: dr46014
3 Replies

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

8. Shell Programming and Scripting

lookup in unix

Hi All I have got a fixed length file of 80bytes long.The first 4bytes of each record represents a client_number.I need to modify the client number based on another lookup file. The lookup file contains 2 fields and a comma delimited file.The first line of the lookup file contains the header... (5 Replies)
Discussion started by: dr46014
5 Replies

9. UNIX for Dummies Questions & Answers

Lookup with a file

Hi All, i have a variable which has a value in it. RETAILER='JEWL' i have a text file. Name: file.txt file.txt ________ WLG 150 JEWL 60 CVS 240 FLN 120 WND 120 I am trying to write a korn script.the script, based on the value in the RETAILER will do a look up against the... (5 Replies)
Discussion started by: pavan_test
5 Replies

10. UNIX for Dummies Questions & Answers

Unix 8.2 and reverse Lookup

We have Unix configured as our external DNS, forward DNS is working properly, however Reverse lookup is not working. Any idea what the problem is? I have checked the named.boot and .rev file and everything seems to be correctly. However it appears that the reverse zone file in the named.boot... (2 Replies)
Discussion started by: cassy
2 Replies
Login or Register to Ask a Question