adding fields to a CSV and converting the delimiter , to tab

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
matthiasR
Pro Scripter
Posts: 52
Joined: Tue Jan 20, 2004 3:45 pm
Location: Lübbecke, Germany

adding fields to a CSV and converting the delimiter , to tab

Post by matthiasR » Sun Feb 26, 2006 12:57 pm

Hi,

I have to modify an existing csv file.

the original csv file is like this e.g.

123456,DE,meier,23532,munich
325632,DE,winkler,32312,berlin
and so on

i then have to add fields to each line. Some fields have to be added before each line ansd some between the fields of the original. So the new csv looks like this for example

000161616,xxxxx,123456,DE,meier,23532,zzzzz,munich,yyyy
000161616,aaaa,325632,DE,winkler,32312,qqqq,berlin,mmmm
and so on.

Some fields to be added have always the same value and some are different.

After the fields are added, the "," should be replaced by "tab", as the target system does not accept any other csv-files than delimited by "tab".

Any idea how i can solve this.

Maybe you can give me a hint, how i can read the source file field by field and how i can write the target file field by field.

Best regards,

Matthias

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Feb 26, 2006 3:25 pm

Look in the help file at the following topics:

Separate
ReadLn
WriteLn
StringReplace

With Separate you can very easily explode the line into separate variables, then all you need to do is use them in a new output line and you can order them how you like and use whatever delimiter you want.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

matthiasR
Pro Scripter
Posts: 52
Joined: Tue Jan 20, 2004 3:45 pm
Location: Lübbecke, Germany

Post by matthiasR » Mon Feb 27, 2006 11:54 am

Thank you very much.
but how do enter the , as the delimiter in the seperate command?
I tried the following

Let>k=1
Label>start
ReadLn>c:\report\stock.txt,k,line
If>line=##EOF##,finish
Seperate>line,",",field
Let>k=k+1
Goto>start
Label>finish

My test source file has just 3 lines
"2342352345",6.00
"kqzw332225",10.00
"125325",1.00

After the first loop the watch list shows me the following field variables
",FIELD_1=
",FIELD_2=2342352345
",FIELD_3=,6.00

Any idea?

Best regards,

Matthias

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Feb 27, 2006 11:58 am

Let>delimiter=,
Separate>line,delimiter,fields
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts