Script for reading .csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for reading .csv file
# 1  
Old 11-09-2007
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  
Old 11-09-2007
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  
Old 11-12-2007
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  
Old 11-12-2007
Thanks for your replies ....

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

Many Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

1. This will insert the records into db table by reading from ta csv file

I have this code with me but the condition is If any of the mandatory columns are null then entire file will be rejected. LOAD DATA infile ' ' #specifies the name of a datafile containing data that you want to load BADFILE ' ' #specifies the name of... (1 Reply)
Discussion started by: raka123
1 Replies

2. Shell Programming and Scripting

Reading CSV file

Hi experts, Im having csv file with few columns which should contain data as shown below. Want to check if column 3 contain row with duplicate value(9876,9876) then corresponding to this in col2 should contain text "tax" and should not contain text "non". Word "non" can come but if in column3... (2 Replies)
Discussion started by: as7951
2 Replies

3. Shell Programming and Scripting

Reading the value of particular column from csv file

Hi Folks, I have the below csv file which is comma delimited , now from this file i need to read the value of the column der_id and then want to create a separate text file which will contain the value of the column der_id only please advise how to read the value of the column der_id and then... (3 Replies)
Discussion started by: punpun66
3 Replies

4. Shell Programming and Scripting

Reading last line of a CSV file

Hi I have a file which I am reading line by line and processing it. But the last line is not getting read in the file loop until I put an enter in the end. #!/bin/ksh -p v_org_id=${P1} FILE=${P2} NEW_FILE_NAME=$APPLPTMP/b1.txt BAKIFS=$IFS IFS=$'\n' exec 0<"$FILE" echo "File to be... (2 Replies)
Discussion started by: Chinky23
2 Replies

5. Shell Programming and Scripting

Reading a csv file using shell script

Hello All, I have a csv file that looks like below ProdId_A,3.3.3,some text,some/text,sometext_1.2.3 ProdId_B,3.3.3,some text,some/text,sometext_1.2.3 ProdId_C,3.3.3,some text,some/text,sometext_1.2.3 ProdId_A,6.6.6,some text,some/text,sometext_9.9.9 I will get ProdId from... (5 Replies)
Discussion started by: anand.shah
5 Replies

6. Shell Programming and Scripting

Reading from a CSV and writing in same CSV file

Hi, I am tryng to read from a csv file and based on some grep command output I will modify one of the column in the same csv. Example:- Input CSV:- 20120829001415,noneAA,google.com 20120829001415,dfsafds,google.com 20120829001415,noneAA,google.com Intermediate Step:- If 2nd column of... (3 Replies)
Discussion started by: kmajumder
3 Replies

7. Shell Programming and Scripting

Reading the data from CSV and performing search through shell script

Hello, I am working on building a script that does the below actions together in my Linux server. 1) First, have to read the list of strings mentioned in CSV and store it in the shell script 2) Second, pick one by one from the string list, and search a particular folder for files that... (2 Replies)
Discussion started by: vikrams
2 Replies

8. Shell Programming and Scripting

Reading variables from CSV file

Hi I am using KSH and trying to read variables from a csv file. I've set the IFS=, and it workds. Problem is where one of the values is text containing a comma. For example the following lines exist in my file. How can I read everything between the quotes into a single variable? APW13812,,1... (2 Replies)
Discussion started by: ventris
2 Replies

9. UNIX for Advanced & Expert Users

Issue reading csv file

HI All I have csv file containing the data like this Electrical Equipment,ElecEquip "Engineering, Machinery & Equipment",Engineerin Entertainment & Broadcasting,Entertain The first and third record are fine,The issue with second records as it has comma enclosed with in inverted... (1 Reply)
Discussion started by: mohdtausifsh
1 Replies

10. Shell Programming and Scripting

reading from a .csv file

Hi , Can anyone please help me to read the value from the .csv file? This is my .csv file: dirnames: first,second i want to get the two names and create directories correspondingly (1 Reply)
Discussion started by: novice_user
1 Replies
Login or Register to Ask a Question