The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 10:20 AM
Script for reading an input file gzs553 Shell Programming and Scripting 1 10-17-2006 07: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 05:25 AM
script to reading a file vasikaran UNIX for Dummies Questions & Answers 3 07-26-2005 06:28 AM
Reading a file into a C++ script Breen High Level Programming 1 10-08-2003 07:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-09-2007
creativeworld creativeworld is offline
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
  #2 (permalink)  
Old 11-09-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
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}
  #3 (permalink)  
Old 11-12-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
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
  #4 (permalink)  
Old 11-12-2007
creativeworld creativeworld is offline
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0