in reply to Aggregating Lines from a CSV who lines match a particular field and save those matches based on that matching field name

Here is a one-liner:
perl -naF, -e '$F[0] eq $prev or close FIL,open FIL,qq|>>|, $F[0] . q +q|.txt|;print FIL $_;$prev=$F[0]' mycsv.csv
Where the input file (sorted text file) is mycsv.csv .

If you are on Windows, use double-quotes instead of single.

Update: Changed OPEN to APPEND instead of overwrite, which seems to be what the OP wants.

     ..to maintain is to slowly feel your soul, sanity and sentience ebb away as you become one with the Evil.

  • Comment on Re: Aggregating Lines from a CSV who lines match a particular field and save those matches based on that matching field name
  • Download Code

Replies are listed 'Best First'.
Re^2: Aggregating Lines from a CSV who lines match a particular field and save those matches based on that matching field name
by ikegami (Patriarch) on Dec 10, 2008 at 06:19 UTC

    Changed OPEN to APPEND instead of overwrite, which seems to be what the OP wants.

    He was forced to use append because he reopened the file for every line. There's no evidence either way as to what he wants to do.

      Thank you BOTH so MUCH

      I did want to append so as each time a line was matched the first field, it would be appended to the file if it had already previously been shown to exist

      I am deeply in awed by both of your mastery!

      Netwallah that was also quite sophisticated to fit it into one line.

      I wish to thank you with a haiku. Not that I am a good poet but I will try.

      A haiku to Ikegami:

      Come new winter,

      Code perfect Ikegami’s

      Perl is a beauty

      A haiku to Netwallah

      Perl does flows through you

      Short but cool like a melting

      Icicle in spring

      I will redouble my efforts to learn Perl better. Thank you again SOOOOOOOO MUCH!!!!!