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
Convert Epoch time format to normal date time format in the same file rk4k Shell Programming and Scripting 3 11-19-2008 10:04 PM
To convert multi format file to a readable ascii format gaur.deepti UNIX for Dummies Questions & Answers 5 03-25-2008 03:03 PM
Convert UTF8 Format file to ANSI format rajreddy UNIX for Dummies Questions & Answers 9 05-25-2007 08:26 AM
Convert UTF8 Format file to ANSI format rajreddy UNIX for Advanced & Expert Users 1 05-24-2007 06:40 AM
convert mmddyy date format to ccyyddd format?? Bhups Shell Programming and Scripting 2 09-27-2006 11:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-09-2008
azs0309 azs0309 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 8
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 (permalink)  
Old 12-09-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
Code:
undef $/;
open FH,"<a.txt";
$str=<FH>;
$str=~tr/\n/,/d;
@arr=split(",",$str);
map {$_=~s/.*=//;} @arr;
print join ",", @arr;
  #3 (permalink)  
Old 12-09-2008
demwz demwz is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 128
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 (permalink)  
Old 12-09-2008
azs0309 azs0309 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 8
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 (permalink)  
Old 12-09-2008
azs0309 azs0309 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 8
Hi summer_cherry

Thanks for the help but the script is not giving me any output.
  #6 (permalink)  
Old 12-09-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Could you post a bigger sample (more than one logical record) of your data?
  #7 (permalink)  
Old 12-09-2008
azs0309 azs0309 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 8
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
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 11:57 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