Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Obtain CSV File from text

by Tux (Abbot)
on Mar 06, 2014 at 15:19 UTC ( #1077239=note: print w/replies, xml ) Need Help??

in reply to Obtain CSV Fiile from text

That line comes from a CSV producer. Is it possible to ask (them) to add a field that *only* has the source file?

  • What if the file name becomes a URI?
  • What if the file name will contain spaces?
  • What if the comment changes?
  • What if the file name will contain special characters like " or ,, that are totally valid in file names?
  • What if the file name is case(in)sensitive?
  • What if the path becomes relative or starts with a drive letter?

Assuming the line comes out the file named export.csv, you could try an overly safe approach like this:

$ cat export.csv 3,"2014-02-19 14:29:05","Extracted 1 Unfulfilled Reconciliation record +s into /opt/mysql/backup/recon/201312/input/UNFULFILLED_RECONCILIATIO +N_20130225.CSV","URECONCILIATION" $ perl -MText::CSV_XS=csv -wE'for(@{csv(in=>"export.csv")}){say for ma +p{s/.* into //i;$_}grep/\.csv/i=>@$_}' /opt/mysql/backup/recon/201312/input/UNFULFILLED_RECONCILIATION_201302 +25.CSV $

Requires Text::CSV_XS-1.04, but it is a one-liner now.

Enjoy, Have FUN! H.Merijn

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1077239]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2018-06-18 05:00 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (108 votes). Check out past polls.