#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Convert list with headers into CSV


    A txt document lists ITEMS under a REFERENCE to which they belong.
    Each ITEM is a string of word characters and spaces on a single line.
    Each REFERENCE is a string of two digits followed by a hyphen followed by three digits.
    The number of items under each reference varies between one and thirty.

    Can a regex help me add the corresponding REFERENCE to every ITEM line.
    In other words, I need to get from there:

    11-111
    itemA
    itemB
    22-222
    itemC
    33-333
    itemD
    itemE
    itemF

    to here:

    11-111,itemA
    11-111,itemB
    22-222,itemC
    33-333,itemD
    33-333,itemE
    33-333,itemF

    Any help or hints of the right approach would be greatly appreciated.

    PS - I am not sure of my regex flavor. I use a text editor in Max OS X called "TextWrangler" with GREP searching...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    Hmm, it is easy to do that with a programming language using regexes, doing that in pure regexes, I am not sure how it could be done.

IMN logo majestic logo threadwatch logo seochat tools logo