Help needed to convert delimited to CSV format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed to convert delimited to CSV format
# 1  
Old 01-29-2009
Help needed to convert delimited to CSV format

I have a file with the data as follows..

FILE 1|#START|Jan 22 15:03
FILE 1|#END|Jan 22 16:06
FILE 2|#START|Jan 22 5:15
FILE 2|#END|Jan 22 5:25
FILE 3|#START|Jan 22 07:03
FILE 3|#END|Jan 22 08:15
FILE 4|#START|Jan 22 16:09
FILE 4|#END|Jan 22 16:55
FILE 1|#START|Jan 22 18:15
FILE 1|#END|Jan 22 18:25

I need to get a .csv file with the format
FILE NAME,START TIME,END TIME

The problem is for the file FILE1,there are two entries...When i am trying to get that format using a loop i am getting second END time,(overcoming first END time)..Can u people suggest some solution...
# 2  
Old 01-29-2009
Each entry should be on its own line, no matter how many times that line appears. For the example you gave, you have two start times and two end times. What is the problem? What script are you using?
# 3  
Old 01-29-2009
Not sure if it's what you want, but here you go:

Code:
awk -F\| 'BEGIN{OFS=","} $2 ~ /START/ {n=$1; t=$3; next} $2 ~ /END/ && $1 == n {print n,t,$3}' infile
FILE 1,Jan 22 15:03,Jan 22 16:06
FILE 2,Jan 22 5:15,Jan 22 5:25
FILE 3,Jan 22 07:03,Jan 22 08:15
FILE 4,Jan 22 16:09,Jan 22 16:55
FILE 1,Jan 22 18:15,Jan 22 18:25

# 4  
Old 01-29-2009
Similar to zaxxons approach:
Code:
awk 'BEGIN{FS="|"; } $2~/START/{printf "%s,%s,",$1,$3} $2~/END/{print $3}' infile

# 5  
Old 01-29-2009
Quote:
Originally Posted by pludi
Similar to zaxxons approach:
Code:
awk 'BEGIN{FS="|"; } $2~/START/{printf "%s,%s,",$1,$3} $2~/END/{print $3}' infile



Thanks a ton for ur reply..but the problem is if a FILE has more than one entry,each having their corresponding start and end times..I wrote a while loop to get the following format(.csv file)
FILE NAME,START TIME,END TIME

But i am not gettin correspondin end time using this loop.I am getting the last end time(for the files which have more than one entry)
# 6  
Old 02-05-2009
Have you solved this problem yet?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX/PERL script to convert XML file to pipe delimited format

Hello, I need to get few values from a XML file and output needs to be written in another file with pipe delimited format. The Header & Footer of the Pipe Delimited file will be constant. The below is my sample XML file. I need to pull the values in between the XML tags <Operator_info to... (15 Replies)
Discussion started by: karthi1305561
15 Replies

2. Shell Programming and Scripting

How to convert space&tab delimited file to CSV?

Hello, I have a text file with space and tab (mixed) delimited file and need to convert into CSV. # cat test.txt /dev/rmt/tsmmt32 HP Ultrium 6-SCSI J3LZ 50:03:08:c0:02:72:c0:b5 F00272C0B5 0/0/6/1/1.145.17.255.0.0.0 /dev/rmt/c102t0d0BEST /dev/rmt/tsmmt37 ... (6 Replies)
Discussion started by: prvnrk
6 Replies

3. Shell Programming and Scripting

Convert csv to pipe delimited except the ones in double quotes

I have a csv data file : A,B,C,D,"A,B",E,"GG,H" E,F,G,H,I,J,"S,P" I need to replace all "," with "|" except the ones between double quotes i.e A|B|C|D|"A,B"|E|"GG,H" E|F|G|H|I|J|"S,P" CAn someone assist? (8 Replies)
Discussion started by: Shivdatta
8 Replies

4. UNIX for Dummies Questions & Answers

How to convert a text file into tab delimited format?

I have a text file that made using text editor in Ubuntu. However the text file is not being recognized as space or tab delimited, the formatting seems to be messed up. How can I convert the text file into tab delimited format? (3 Replies)
Discussion started by: evelibertine
3 Replies

5. Shell Programming and Scripting

Convert the below file to csv format

Hi , i want to change this question, i will post soon.. (6 Replies)
Discussion started by: srikanth2567
6 Replies

6. UNIX for Advanced & Expert Users

Urgent! need help! how to convert this file into comma delimited format

Hi experts, I need urget help! I have the a text file with this format: Types of fruits Name of fruits 1,1 Farm_no,1 apple,1 pineapple,1 grapes,1 orange,1 banana,1 2,2--->this is the record seperator Farm_no,2 apple,1 pineapple,1 grapes,3 orange,2 banana,1 3,3--->this is the... (2 Replies)
Discussion started by: natalie23
2 Replies

7. Shell Programming and Scripting

how to convert this file into comma delimited format

Hi experts, I need urget help! I have the a text file with this format: Types of fruits Name of fruits 1,1 Farm_no,1 apple,1 pineapple,1 grapes,1 orange,1 banana,1 2,2--->this is the record seperator Farm_no,2 apple,1 pineapple,1 grapes,3 orange,2 banana,1 3,3--->this is the... (1 Reply)
Discussion started by: natalie23
1 Replies

8. Shell Programming and Scripting

Convert XML to CSV format

Can any one give the idea on this, please. I have the following XML file and wants to convert into CSV(comma separated value) format. <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE Waveset PUBLIC 'waveset.dtd' 'waveset.dtd'> <Waveset> <Object name='ra8736'> <Attribute name='ADDRESS'... (2 Replies)
Discussion started by: kumar04
2 Replies

9. Shell Programming and Scripting

convert files into csv format using perl

Hi all perl gurus, I need your help to get the desired output in perl. I have a file which has text in it in the format Connection request start timestamp = 12/08/2008 00:58:36.956700 Connect request completion timestamp = 12/08/2008 00:58:36.959729 Application idle time ... (10 Replies)
Discussion started by: azs0309
10 Replies

10. Shell Programming and Scripting

Convert a csv file to an xls format

Hi, I have a file coming in xxx.txt(csv format) i do some work on it and i need to send out as a .xls format. Is there any way there is some code i can use in my script to convert this? I'm struggling on this. Thanks (11 Replies)
Discussion started by: Pablo_beezo
11 Replies
Login or Register to Ask a Question