The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script for Reading a Password file srirams Shell Programming and Scripting 2 03-07-2007 07:20 AM
Script for reading an input file gzs553 Shell Programming and Scripting 1 10-17-2006 03:55 AM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 02:25 AM
script to reading a file vasikaran UNIX for Dummies Questions & Answers 3 07-26-2005 02:28 AM
Reading a file into a C++ script Breen High Level Programming 1 10-08-2003 03:04 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-09-2007
Registered User
 

Join Date: Nov 2007
Posts: 2
Script for reading .csv file

Can someone please help me to write script for following scenario :

1> script should read a input .csv file of format : EmpName, PF, Leave, Basic ,HRA
2> another config file ( may be again a .csv file ) has format EmpName and EmpID
3> script should read another config file for each EmpName in the input file , to find the EmpID
4> After finding EmpID from config file, all records need to be written in 3rd file ( output file ) with format : EmpName ,EmpID ,PF, Leave ,Basic ,HRA

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 11-09-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Here's something to start with.

nawk -F',' -v OFS=':' -f emp.awk conf.csv input.csv

emp.awk:
Code:
NR==FNR { a[$1] = $2; next }
$1 in a { $1=$1 OFS a[$1]; print}
Reply With Quote
  #3  
Old 11-11-2007
Registered User
 

Join Date: Jun 2007
Location: Beijing China
Posts: 495
awk

Hi,

input:
Code:
a:
leo pf1 leave1 basic1 hra1
james pf2 leave2 basic2 hra2
tony pf3 leave3 basic3 hra3
b:
leo 210375
james 210075
tony 210378
output:
Code:
leo 210375 pf1 leave1 basic1 hra1
james 210075 pf2 leave2 basic2 hra2
tony 210378 pf3 leave3 basic3 hra3
code:
Code:
awk '
{
if (NF==2)
id[$1]=$2
else
print $1,id[$1],$2,$3,$4,$5
}' b a
Reply With Quote
  #4  
Old 11-11-2007
Registered User
 

Join Date: Nov 2007
Posts: 2
Thanks for your replies ....

I'm unaware of awk programming .... can you please explain me the logic used here ??

Many Thanks
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0