From: Robert Klemme Date: 2003-10-08T17:48:05+09:00 Subject: Re: Parsing challenge... "Artco News" schrieb im Newsbeitrag news:CTDgb.31522$yU5.13084@nwrdny01.gnilink.net... > I thought I ask the scripting guru about the following. > > I have a file containing records of data with the following format(first > column is the label): > > CODE#1^DESCRIPTION^CODE#2^NOTES > NN-110^an info of NN-001^BRY234^some notes > NN-111^1st line data > 2nd line data > 3rd line data^BRT345^another notes > NN-112^description of NN-112^BBC23^multiline > notes blah > blah > blah > NN-113^info info^MNO12^some notes here > > How do I parse so I can insert them in the database, e.g. MySQL/Access? > > Perhaps there are an advanced scripting language can do this easily. Ruby: #!/usr/bin/ruby def process(rec) while rec.size > 4 dbRec = rec.slice!( 0..3 ) # db insertion here p dbRec end end rec = [] while ( line = gets ) line.chomp! rec.concat( line.split('^') ) process rec end process rec