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

Re: substring/regex question

by Loops (Curate)
on Aug 06, 2013 at 04:12 UTC ( #1048045=note: print w/replies, xml ) Need Help??

in reply to substring/regex question

Since your data is in comma separated format, using an absolute offset to extract the number you want doesn't make sense. You can use the Text::CSV module to parse the data into separate fields:

use Text::CSV; my $file = "trace.csv"; my $file1 = "rgextract.txt"; open my $io, '<', $file or die "$file: $!"; open my $out, '>>', $file1 or die "$file1: $!"; my $csv = Text::CSV->new({ binary => 1, eol => $/ }); while (my $row = $csv->getline ($io)) { my $number = $row->[3]; print $out "$number\n"; }
With the 4 data lines you posted, this will create the rgextract.txt file:
114 118 114 114

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048045]
[marinersk]: Ah, you beat me to it.
[LanX]: as long as he has votes left, the nodelet remains
[LanX]: There is a very simple solution ...
[marinersk]: Correct, so one workaround is to leave one vote.
[marinersk]: But I was looking for a more elegant solution. It appears noone online at this time is aware of one.
[LanX]: go to Nodelet Settings and click "All nodelets off"
[marinersk]: LanX++ LOL Yes, that is another workaround. :-)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-05-29 14:14 GMT
Find Nodes?
    Voting Booth?