Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Obtain CSV File from text

by Tux (Monsignor)
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


Comment on Re: Obtain CSV File from text
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1077239]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-12-26 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (168 votes), past polls