Hi poj, thank you so much for your help, this is the first solution that does the job, but only, when the newlines were also re-inserted in the so called Header or tags, that are the strings starting with a square bracket. As you might have supposed, its a special text file with chess moves, but each of the square brackets has to be on its own line, otherwise a chess program can not interpret the file. As I'm new to perl, I have to work hard to understand your code, but I will try my best. The line: $line =~ s/ (\d+\. )/\n$1/g; does to my understanding the job of re-inserting the newlines but only with the numbered lines. I have added the line: $line =~ s/ (\[ )/\n$1/g; and I had hoped this will re-install the newlines for the tags, but for no good. If you can post a solution with newlines also for the tags, I would be very thankful to you.
| [reply] |
$line =~ s/\n/ /g;
I don't understand this statement in poj's code: why are all newlines being changed to spaces?
$line =~ s/ (\d+\. )/\n$1/g;
This statement seems to speak to a requirement to add newlines before every 1. 23. 345. pattern, but I can't see where this has ever been discussed before. Please give more info on this.
It would help if you could post a short example of an input file and a corresponding file representing the exact output you want from it. By short, I mean that most of the data in the input file you have already posted seems redundant; please try to keep example data short and sweet.
And once again, the statement that the result of a piece of code is "no good" is not helpful; in what way is it no good? You should say "With this code and this input data, I want to get 'XXX' and I am getting 'YYY'."
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |
#!perl
# Aufruf: perl removeEK1.pl TestEK.txt > Out.txt
use strict;
use warnings;
my $regex = '{\[%tqu[^\]]*]}';
my $line = do { local $/; <>; };
$line =~ s/\n/ /g;
$line =~ s/$regex//gi;
$line =~ s/ (\d+\. |\[)/\n$1/g;
print $line;
poj | [reply] [d/l] |
#!/usr/bin/perl
# Remove extra text from a PGN or Text-file.
use strict;
use warnings;
my $regex = '{\[%tqu[^\]]*]}';
my $line = do { local $/; <>; };
$line =~ s/\n/ /g;
$line =~ s/$regex//gi;
# these statements I have inserted
$line =~ s/\]/\]\n/g;
$line =~ s/\[E/\n\[E/g;
# end
$line =~ s/ (\d+\. )/\n$1/g;
print $line;
and it "nearly" worked, but I got an empty first line in the outputfile.
| [reply] [d/l] |