Fixed length file editing

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
Michael Cook

Fixed length file editing

Post by Michael Cook »

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
Michael Cook

Additional info

Post by Michael Cook »

I don't know if it matters, but the second line of each record can be characterized by starting with several spaces.
User avatar
s_reynisson
Posts: 939
Joined: Tue May 06, 2003 1:59 pm

Re: Additional info

Post by s_reynisson »

These spaces on the second line, same number each time?
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
Michael Cook

Post by Michael Cook »

All of the second lines have the same number of spaces at the beginning.

Joining the two lines will cause the fields from the second line to not match up, because the last field from line one varies in length.

Thanks
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

To be clear, you want to do this (using ...... for spaces):

FROM something like this:
Line1234567890123456
.....Line234567890
Line345678901234567890123
.....Line456789012
Line5678901234
.....Line678901234
TO something like this:
Line1234567890123456.....Line234567890.........
Line345678901234567890123.....Line456789012
Line5678901234.....Line678901234...................
OR something like this:
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
Michael Cook

Post by 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.
User avatar
s_reynisson
Posts: 939
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

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
Then I open up and see
the person fumbling here is me
a different way to be
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

:idea: So now you can make a batch file using grep commands with s_reynisson's expressions. Add the batch file as a Tool to Textpad and you can do this process with a hot-key or a mouse click.
Hope this was helpful.............good luck,
Bob
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Step 2 and step 3 can be done in one go, you simply have to replace $ by \n, so the \n is found as well:

2. Chop first line to a fixed length (30 here)

^([^ ].{29,29}).*\n
\1

And instead of a batch job, this two-step operation could also be saved as a textpad macro.
Post Reply