[Solved] Perl Question - split function with csv file | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

[Solved] Perl Question - split function with csv file

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-23-2013
WongSifu WongSifu is offline
Registered User
 
Join Date: Apr 2012
Last Activity: 23 January 2013, 1:19 PM EST
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
[Solved] Perl Question - split function with csv file

Hi all,

I have a csv file that appears as follows:


Code:
,2013/03/26,2012/12/26,4,1,"2017/09/26,5.75%","2017/09/26,1,2018/09/26,1,2019/09/26,1,2020/09/26,1,2021/09/26,1",,,2012/12/26,

now when i use the split function like this:


Code:
my @f  = split/,/;

the split function will split the data that is within the ".

What I need to do is still split based on a "," but not look at the "," that are in the quotes.

I'm pretty stumped here. Any help would be greatly appreciated.

Last edited by radoulov; 01-23-2013 at 01:41 PM.. Reason: Marked as solved.
Sponsored Links
    #2  
Old 01-23-2013
balajesuri's Avatar
balajesuri balajesuri is online now Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 24 April 2014, 12:15 PM EDT
Location: India
Posts: 1,799
Thanks: 23
Thanked 516 Times in 495 Posts

Code:
#! /usr/bin/perl
use Text::ParseWords "quotewords";
open F, "< file";

while (<F>) {
    chomp;
    @new = quotewords(",", 0, $_);
    for (@new) { print "$_ || " }
    print "\n";
}

close F;


Code:
$ ./test.pl
 || 2013/03/26 || 2012/12/26 || 4 || 1 || 2017/09/26,5.75% || 2017/09/26,1,2018/09/26,1,2019/09/26,1,2020/09/26,1,2021/09/26,1 ||  ||  || 2012/12/26 ||  ||

The Following User Says Thank You to balajesuri For This Useful Post:
PikK45 (01-23-2013)
Sponsored Links
    #3  
Old 01-23-2013
WongSifu WongSifu is offline
Registered User
 
Join Date: Apr 2012
Last Activity: 23 January 2013, 1:19 PM EST
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
works!!! thanks!!!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl split function vishwakar Shell Programming and Scripting 3 09-16-2011 10:47 AM
split xlsx to csv using perl malikshahid85 Programming 1 08-18-2010 04:10 AM
PERL split function castle Shell Programming and Scripting 1 02-21-2010 05:28 AM
Use split function in perl chriss_58 Shell Programming and Scripting 5 06-13-2008 05:50 AM
perl split function new2ss Shell Programming and Scripting 5 06-08-2006 10:17 PM



All times are GMT -4. The time now is 12:28 PM.