|
View previous topic :: View next topic
|
| Author |
Message |
tuxama
New User
Joined: 25 Jan 2007 Posts: 42 Location: france
|
|
|
|
Hello,
Does anyone have a solution to propose: How to move the first field of each record to the end of the record in a CSV file ?
My input file contains multiple fields, each separated from the previous one by a semicolon
The problem seemed trivial to me, but I don't see a simple solution.
The problem also comes from the fact that we don't know the number of fields.
Of course, it is not impossible that SPACE characters are present in one or more fields.
I starded with :
| Code: |
OUTFIL VTOF,
PARSE=(%01=((ABSPOS=1,ENDBEFR=C'";',FIXLEN=2),
%02=( ? )),
BUILD=(%02,C';',%01)
|
But I don't know how to reference the end of the record.
Thank you in advance for your help.
Best regards |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2272 Location: USA
|
|
|
|
First of all, while working with RECFM=VB, in SORT you need to take into account RDW field, in every record.
| Code: |
"1";22222;33333;44444;55555;66666
"2";AAAAA;BBBBB;CCCCC;DDDDD;EEEEE;FFFFF;GGGGG
"3";999;888;777;666;555;444 |
| Code: |
SORT FIELDS=COPY
OUTREC PARSE=(%01=(ABSPOS=5,ENDBEFR=C'";',FIXLEN=2),
%02=(FIXLEN=80)),
BUILD=(1,4,%02,JFY=(SHIFT=RIGHT),C';',%01,C'"')
OUTFIL VTOF,
PARSE=(%03=(ABSPOS=5,STARTAFT=C' ',FIXLEN=100)),
BUILD=(%03,JFY=(SHIFT=LEFT)) |
| Code: |
22222;33333;44444;55555;66666;"1"
AAAAA;BBBBB;CCCCC;DDDDD;EEEEE;FFFFF;GGGGG;"2"
999;888;777;666;555;444;"3" |
|
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1430 Location: Bamberg, Germany
|
|
|
|
No need for a second parse operation.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(ABSPOS=5,ENDBEFR=C'";',FIXLEN=2),
%02=(FIXLEN=80)),
BUILD=(1,4,%02,JFY=(SHIFT=RIGHT,TRAIL=C';'),%01,C'"')),
IFTHEN=(WHEN=INIT,BUILD=(1,4,5,83,JFY=(SHIFT=LEFT,LENGTH=80)))
END |
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2272 Location: USA
|
|
|
|
| Joerg.Findeisen wrote: |
No need for a second parse operation.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(ABSPOS=5,ENDBEFR=C'";',FIXLEN=2),
%02=(FIXLEN=80)),
BUILD=(1,4,%02,JFY=(SHIFT=RIGHT,TRAIL=C';'),%01,C'"')),
IFTHEN=(WHEN=INIT,BUILD=(1,4,5,83,JFY=(SHIFT=LEFT,LENGTH=80)))
END |
|
Anyway, OUTFIL VTOF is required... |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1430 Location: Bamberg, Germany
|
|
|
|
| This for sure. |
|
| Back to top |
|
 |
tuxama
New User
Joined: 25 Jan 2007 Posts: 42 Location: france
|
|
|
|
Hello,
Thank you very much for your help, it perfectly solved my problem.
The issue with the RDW was due to a transcription error because I did not use the copy/paste function.
However, I am delighted to see that this error did not go unnoticed, as it is also a mistake of carelessness that I easily make.
Thank you again.
best regards |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|