yesimnewinperl has asked for the wisdom of the Perl Monks concerning the following question:

Hello gurus. I've never used PERL before, but I know it can help me doing this so I'm asking a very simple question.

There's a folder which contains many *.txt files. Each file contains several tables inside. Each table has its header. Headers are same in all files but number of rows different.

Headers are separated from previous table with empty string symbol. There's no empty string between a header and a table below it.

1. I need to split each of these text files into multiple text files using empty strings in each file as delimiters and naming each file as the header is.

2. I need to combine several output text files into one table

For example: SOURCE_FILE.txt:
HEADER_1

X Y Z

1 2 3



HEADER_2

X Y Z

4 5 6

AFTER STEP 1:


HEADER_1.txt

X Y Z

1 2 3


HEADER_2.txt

X Y Z

4 5 6

AFTER STEP 2:


OUTPUT.txt

X Y Z X Y Z

1 2 3 4 5 6

Thanks and regards!

  • Comment on Split text file into multiple using empty string criteria

Replies are listed 'Best First'.
Re: Split text file into multiple using empty string criteria
by sauoq (Abbot) on May 16, 2012 at 22:11 UTC
    Headers are separated from previous table with empty string symbol. There's no empty string between a header and a table below it.

    I think you need some assistance with the terminology you use first. The empty string is a string of zero length. In a string with one character like "x", there are two empty strings, one after and one before the 'x'.

    From your examples, it seems that you might be calling a space between columns an "empty string" but I'm not sure. Maybe you mean "whitespace". Maybe you mean tabs. Maybe you mean nulls. You also seem to be calling blank lines "empty strings" but again, I'm unsure.

    -sauoq
    "My two cents aren't worth a dime.";