Andrej Kastrin am Montag, 16. Januar 2006 14.32:
> Hi all,
>
> I have the file, which looks like:
>
> *RECORD*
> *ID*
> 001
> *TITLE*
> Here is title number one.
> *ABSTRACT*
> First sentence of the abstract. Second sentence of the abstract...
> Second line of the abstract.
>
> *RECORD*
> *ID*
> 002
> *TITLE*
> Here is title number one.
> *ABSTRACT*
> First sentence of the abstract. Second sentence of the abstract...
> Second line of the abstract.
>
> Is there any simple way to transform this file to look like:
> *RECORD*
> *ID* 001
> *TITLE* Here is title number one.
> *ABSTRACT* First sentence of the abstract. Second sentence of the
> abstract. Second line of the abstract.
>
> Thanks in advance for any pointers or notes.
>
> Cheers, Andre
The following does what you want in a somehow generic way (except from the
additional empty line at the very end), but it is more short than simple, and
there must exist an easier regex I have not found:
use strict; use warnings;
local $/="";
while(<DATA>) {
s/((?<=\*)|(?<!\*))\n(?!\*|$)/ /gms;
print;
}
__DATA__
*RECORD*
*ID*
001
*TITLE*
Here is title number one.
*ABSTRACT*
First sentence of the abstract. Second sentence of the abstract...
Second line of the abstract.
*RECORD*
*ID*
002
*TITLE*
Here is title number one.
*ABSTRACT*
First sentence of the abstract. Second sentence of the abstract...
Second line of the abstract.
### prints:
*RECORD*
*ID* 001
*TITLE* Here is title number one.
*ABSTRACT* First sentence of the abstract. Second sentence of the abstract...
Second line of the abstract.
*RECORD*
*ID* 002
*TITLE* Here is title number one.
*ABSTRACT* First sentence of the abstract. Second sentence of the abstract...
Second line of the abstract.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>