Hi there
I have a text file that looks something like this
filename = without012.csv pred = -0.0105 0.0645 0.1989 0.0151 0.0289 0.0400 0.5313 filename = without013.csv pred = -0.0080 0.0663 0.1911 0.0075 0.0288 0.0302 0.5234 filename = without014.csv pred = -0.0023 0.0595 0.2582 0.0323 0.0285 0.0578 0.5807
And so on. This text file was produced from 120 smaller .csv files, as you can probably guess from the names .. lol. What I need to do is to save each individual 'block' of numeric values .. for example
-0.0023 0.0595 0.2582 0.0323 0.0285 0.0578 0.5807
Into separate files, with each file being saved according to the smaller files from which these results originate. So, for the example below
filename = without014.csv pred = -0.0023 0.0595 0.2582 0.0323 0.0285 0.0578 0.5807
I would like to save the numeric block in a small file called without014.csv.
With this in mind I started writing a perl script as follows:
#!/usr/bin/perl @file = <>; for($i = 0; $i < @file; $i+4) { print "$file[$i]"; }
I was hoping that it would print out just the file names initially and then I was going to use the same technique for extracting the numeric block but all I am getting is blank lines when I run it (and yes, I'm checking that I am attempting to print off 'the right line' lol).
Anyway .. it's obvious that I am not getting very far .. so any suggestions/tips would be much appreciated.

In reply to extracting data and saving into seperate files by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.