Hi,
I have a text file (300,000 lines) in which large chunks of data are seperated by $$$$ and a line feed i.e.

...
3 6 8 09
5 7 9 5
END
$$$$
5 9 0 -7
7 9 3 6
END
$$$$

I have a CSV file which contains data related to each group above. The first row in the CSV is a header row with column names.

My csv looks like

Column 1, Column 2
Data 1, Data 2
Data 3, Data 4

I would like to end up with an output file like:

...
3 6 8 09
5 7 9 5
END
> <Column 1>
Data 1
> <Column 2>
Data 2
$$$$
5 9 0 -7
7 9 3 6
END
> <Column 1>
Data 3
> <Column 2>
Data 4
$$$$

Basically, the csv data has been merged between the END keyword and $$$$. I have tried:

while (<DATAFILE>){ $string = $string.$_; } @individual = split /\$\$\$\$/,$string; foreach $i (@individual){ print "inside outer foreach\n"; foreach $h (@headers){ print "inside header foreach - appending tags\n"; @seperate = $i."> <$h>\n"; } @seperate = $i.'$$$$'; } open (OUT, ">outtest.out"); print OUT @seperate;

What this does is just print '$$$$'.

Any help appreciated.

Thanks - Joe.

@headers came from just reading the first line of the csv


In reply to Appending data to large files by joec_

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.