Need script logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need script logic
# 1  
Old 04-22-2013
Need script logic

i have two csv files (rates.csv, reference.csv) as below.

HTML Code:
rates.csv contains Code, respective Zone details
 
rates.csv
----------
23,38Nhava
45,37NEWYORK
89,SHILANG
71,ROBACCA
HTML Code:
reference.csv contains all Zone details
reference.csv
-------------
37Newyork
robacca
38Nhava
Shilang
Edinburg
Mizoram
i have to cross check the Zone details in rates.csv with the reference.csv file for each row in rates.csv and make changes to Zone as per teh details present in reference.csv.
can someone plz provide a logic for this.
# 2  
Old 04-22-2013
What you are trying to achieve with this two files ?
Can you please show us expected output.

Regards,

pamu Smilie
# 3  
Old 04-22-2013
the rates.csv file should be like below after correction.

Code:
 
rates.csv
----------
23,38Nhava
45,37Newyork
89,Shilang
71,robacca

My intention is to modify the values in 2nd column in rates.csv file as per the details present in reference.csv as we are facing case sensitive issue in subsequent applications.
and as there are no of rows getting inserted each day in the rate.csv file, we want to setup a job to correct it.

Last edited by Scott; 04-22-2013 at 08:38 AM.. Reason: Code tags
# 4  
Old 04-22-2013
You can use join for this, but you'll have to make sure that both files are sorted in the same way:
Code:
join -i -t"," -j1 2 -j2 1 -o 1.1,2.1 rates.csv reference.csv

In order to sort, you can use something like:
Code:
sort -f -t"," rates.csv
sort -f -k2 -t"," reference.csv

# 5  
Old 04-22-2013
Code:
awk -F, 'NR==FNR{A[tolower($0)]=$0;next}{if(A[tolower($2)]){print $1 FS A[tolower($2)]}}' reference.csv rates.csv

# 6  
Old 04-22-2013
Quote:
Originally Posted by Subbeh
You can use join for this, but you'll have to make sure that both files are sorted in the same way:
Code:
join -i -t"," -j1 2 -j2 1 -o 1.1,2.1 rates.csv reference.csv

That will fail everywhere except GNU-land. Just a warning in case the OP is not using Linux.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Solaris

Need script logic

Hi, i have a file which contains names of persons and date as below. peter 27-mar Vicky 08-sep Saryu 03-jan venki 14-dec ..... ... can someone plz provide a script logic, which returns the Name of the person whose date is matching with current date. (5 Replies)
Discussion started by: JSKOBS
5 Replies

2. Shell Programming and Scripting

Script logic

Please help me to write the following script. 1) Input files will be in Test directory. (Test/YYYY/MM) folders (Ex: 1) 2010/ 01 2) 2011/05) The file name will be Testfile1_6676543218_Axxxxxxyyyyyzzzzzzzzzzzzzzzzzz.pdf.gz 2) The compare file will be in /tmp directory. (/tmp/comparefile.txt). The... (6 Replies)
Discussion started by: mnjx
6 Replies
Login or Register to Ask a Question