Read csv file line by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read csv file line by line
# 1  
Old 05-09-2011
Read csv file line by line

Folks ,
i want to read a csv file line by line till the end of file and filter the text in the line and append everything into a variable.

csv file format is :-

Code:
trousers:shirts,price,50
jeans:tshirts,rate,60
pants:blazer,costprice,40

etc

i want to read the first line and get the output with a period "." instead of "," into a variable to be used in other part of the script.

Code:
50 trousers:shirts.price
60 jeans:tshirts.rate
40 pants:blazer.costprice

Your help is appreciated.

Venu

Last edited by joeyg; 05-09-2011 at 03:22 PM.. Reason: Please use CodeTags around scripts and data
# 2  
Old 05-09-2011
What language or shell are you using? What have you done so far?
# 3  
Old 05-09-2011
Does this give you some ideas?

Code:
$ echo trousers:shirts,price,50 | awk -F"," '{print $3 " " $1 "." $2}'
50 trousers:shirts.price

Instead of an echo, you could pass the input file to that awk command.
This User Gave Thanks to joeyg For This Post:
# 4  
Old 05-09-2011
I want to write this in korn shell
# 5  
Old 05-09-2011
Quote:
Originally Posted by venu
I want to write this in korn shell
Why?

Is this a home work assignment?
# 6  
Old 05-09-2011
Quote:
Originally Posted by Franklin52
Why?

Is this a home work assignment?
no..its not an assignment....

---------- Post updated at 07:53 PM ---------- Previous update was at 01:42 PM ----------

Folks,
how do i compare the integer , real and float numbers in the numeric field of the column , i mean the $3 ?

Your help is appreciated.
Venu
# 7  
Old 05-10-2011
I'm a newbie at this and i'm sure someone can write a better script than mine. But this works using sed captures:
Code:
sed -r "s/(^.*),([0-9][0-9])/\2 \1 /" input.txt | sed "s/,/./"


Last edited by Franklin52; 05-10-2011 at 03:04 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

2. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

Honey, I broke awk! (duplicate line removal in 30M line 3.7GB csv file)

I have a script that builds a database ~30 million lines, ~3.7 GB .cvs file. After multiple optimzations It takes about 62 min to bring in and parse all the files and used to take 10 min to remove duplicates until I was requested to add another column. I am using the highly optimized awk code: awk... (34 Replies)
Discussion started by: Michael Stora
34 Replies

5. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

6. UNIX for Dummies Questions & Answers

skip first line when doing a read of csv file

Folks, how do i skip the first line in a csv, while doing the read of a csv file in to a variable line by line. eg : do echo $line done < $rpt where rpt is path to csv file The initial 1st line is a garbage that i want to avoid, and start reading from 2nd line ... (2 Replies)
Discussion started by: venu
2 Replies

7. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

8. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

10. UNIX for Dummies Questions & Answers

read a line from a csv file and convert a column to all caps

Hello experts, I am trying to read a line from a csv file that contains '.doc' and print the second column in all caps. e.g. My csv file contains: Test.doc|This is a Test|test1|tes,t2|test-3 Test2.pdf|This is a Second Test| test1|tes,t2|t-est3 while read line do echo "$line" |... (3 Replies)
Discussion started by: orahi001
3 Replies
Login or Register to Ask a Question