I have some data in a fixed length file, sort of.
Each record is on two consecutive lines. The problem is the first line of each record varies in length, because the last field in the first line varies in length.
How can I get each record on one line with consistent field lengths?
Thanks
Fixed length file editing
Moderators: AmigoJack, bbadmin, helios, MudGuard
-
Michael Cook
Additional info
I don't know if it matters, but the second line of each record can be characterized by starting with several spaces.
- s_reynisson
- Posts: 939
- Joined: Tue May 06, 2003 1:59 pm
Re: Additional info
These spaces on the second line, same number each time?
If not, could this just be a case of joining the two lines?
If not, could this just be a case of joining the two lines?
Michael Cook wrote:I don't know if it matters, but the second line of each record can be characterized by starting with several spaces.
Then I open up and see
the person fumbling here is me
a different way to be
the person fumbling here is me
a different way to be
-
Michael Cook
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
To be clear, you want to do this (using ...... for spaces):
FROM something like this:
Do I have this correct?
(Spaces are shown for visual presentation, may not reflect actual count that would be inserted).
Can spaces be added to end of line as shown in these samples above?
Can the spaces on line 2 be removed?
Can more spaces be inserted betwen lines 1 and 2 so line 2 always starts in same position?
Do you have a preferred length that final line should be?
FROM something like this:
TO something like this:Line1234567890123456
.....Line234567890
Line345678901234567890123
.....Line456789012
Line5678901234
.....Line678901234
OR something like this:Line1234567890123456.....Line234567890.........
Line345678901234567890123.....Line456789012
Line5678901234.....Line678901234...................
Line1234567890123456..............Line234567890
Line345678901234567890123.....Line456789012
Line5678901234........................Line678901234
Do I have this correct?
(Spaces are shown for visual presentation, may not reflect actual count that would be inserted).
Can spaces be added to end of line as shown in these samples above?
Can the spaces on line 2 be removed?
Can more spaces be inserted betwen lines 1 and 2 so line 2 always starts in same position?
Do you have a preferred length that final line should be?
Hope this was helpful.............good luck,
Bob
Bob
-
Michael Cook
Bob Hansen, you have it correct.
I want the data converted to the second example so all the fields line up in columns.
Spaces can be added as shown.
The spaces from line two can be removed.
I think I need spaces to be added between the lines to get line two to start at the same column for each record.
The record length is not important, just that the result is a fixed length field record.
Thanks.
I want the data converted to the second example so all the fields line up in columns.
Spaces can be added as shown.
The spaces from line two can be removed.
I think I need spaces to be added between the lines to get line two to start at the same column for each record.
The record length is not important, just that the result is a fixed length field record.
Thanks.
- s_reynisson
- Posts: 939
- Joined: Tue May 06, 2003 1:59 pm
Best I can do is 3 steps using Regular Expressions w/POSIX:
1. Add lots of spaces to first line
^([^ ].*)$
\1...lots of spaces.....
2. Chop first line to a fixed length (30 here)
^([^ ].{29,29}).*$
\1
3. Join first and second line
^([^ ].+)\n
\1
HTH
1. Add lots of spaces to first line
^([^ ].*)$
\1...lots of spaces.....
2. Chop first line to a fixed length (30 here)
^([^ ].{29,29}).*$
\1
3. Join first and second line
^([^ ].+)\n
\1
HTH
Then I open up and see
the person fumbling here is me
a different way to be
the person fumbling here is me
a different way to be
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
- MudGuard
- Posts: 1295
- Joined: Sun Mar 02, 2003 10:15 pm
- Location: Munich, Germany
- Contact: