convert files into csv format using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convert files into csv format using perl
# 1  
Old 12-09-2008
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 = 1 minute 8 seconds
CONNECT Authorization ID = PDPD240
Client login ID = pdpd240
Configuration NNAME of client = sppwd518

but i want it to be displayed in the format.
12/08/2008 00:58:36.956700,12/08/2008 00:58:36.959729,1 minute 8 seconds

i.e. the left most things to be in a comma seperated value.

The script should take the file name as argument.for eg

perl scriptname <filename>

even a snippett of the code would be fine for me to atleast have an idea how to go ahead
Thanks
# 2  
Old 12-09-2008
Code:
undef $/;
open FH,"<a.txt";
$str=<FH>;
$str=~tr/\n/,/d;
@arr=split(",",$str);
map {$_=~s/.*=//;} @arr;
print join ",", @arr;

# 3  
Old 12-09-2008
Im not a perl programmer and i've not tested this. but basicly it should work

my @start;
my @complete;
my @time;
my $filename=@ARGV[0];
open( FILE, "< $filename" ) or die "Can't open $filename : $!";
while( <FILE> ) {
chomp;
@start = split(/=/) if /start/ ;
@complete = split(/=/) if /completion/;
@time = split(/=/) if /idle time/;
print "@start[1] @complete[1] @time[1] \n" if /NNAME/;
}
# 4  
Old 12-09-2008
hi Demwz,

Its not that i want three line...the input file would be very big but with the format

heading1 = data1
..
..
..

and i want a csv file

data1,data2,....
# 5  
Old 12-09-2008
Hi summer_cherry

Thanks for the help but the script is not giving me any output.
# 6  
Old 12-09-2008
Could you post a bigger sample (more than one logical record) of your data?
# 7  
Old 12-09-2008
Hi radoulov,

The whole file is in the format

head1 = data1
head2 = data2
..
..
..
and so on

and I want the format(all the things after the equal sign)

data1,data2,data3,.... so on
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert listner.log to csv format with comma seperated

Hi All, I am new to shell scripting i am trying to convert the listner.log to csv which can be inturn converted to excel for easy reading. i used this command awk '/SID=/ && /HOST=/ && /PORT=/ && /USER=/ { i=match($0,"SID="); i=i+RLENGTH; h0=substr($0,i); i=match(h0,")");... (6 Replies)
Discussion started by: skoshekay
6 Replies

2. Shell Programming and Scripting

Convert csv data to html format

I am new to html and need to convert the attached csv file data to html format ; running into issues. please assist. #!/bin/ksh echo "<html>" ; echo "<head><style> table {border-collapse: collapse;} table, td, th {border: 1px solid black;} </style></head>" echo "<title> REPORT </title>" echo... (0 Replies)
Discussion started by: archana25
0 Replies

3. Shell Programming and Scripting

Perl script to Convert XLSX or XLS files to CSV file

Hi All, I've got in a situation where I need to convert .xlsx or .xls formatted files into simple text file or .csv file. I've found many options but doing this using PERL script is the best way I believe.I'm in AIX box. Perl code should have 2 params while running. i.e perl... (1 Reply)
Discussion started by: manab86
1 Replies

4. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. Programming

awk script to convert a text file into csv format

hi...... thanks for allowing me to start a discussion i am collecting usb usage details of all users and convert it into csv files so that i can export it into some database.. the input text file is as follows:- USB History Dump by nabiy (c)2008 (1) --- Kingston DataTraveler 130 USB... (2 Replies)
Discussion started by: certteam
2 Replies

6. 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

7. Shell Programming and Scripting

Is there any script which convert binary file to CSV format

Dear guys; I have a binary file and I need to convert its data to csv format ...appreciating your help. Best Regards (14 Replies)
Discussion started by: ahmad.diab
14 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

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... (5 Replies)
Discussion started by: karthikd214
5 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