On Monday 16 January 2006 14:32, Andrej Kastrin wrote:
> Hi all,

Hi Andrej

> 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.

I'm also new to this game, but I'll try:

#!/usr/bin/perl

open FILEHANDLE, "<yourfile.txt" or die "die\n";

#optional
use strict;

#declare array
my @line;

# go trough each line
# shortcut for:
#   my $_;
#   while ( defined ( $_ = <FILEHANDLE> ) ) {
while ( <FILEHANDLE> ) {

    # cut off trailing newline
    # shortcut for:
    #   chomp $_;
    chomp;

    #push the line to the array
    push ( @line, $_ );
}

# join the elements of the array and print them
print join(" ", @line);
close FILEHANDLE;

I guess this should give you some hints about how to manipulate those files of 
yours, since you don't want to join *all* the file in one line. One way can 
be to check for lines beginning with '*' (using regexp /^\*/ or something 
similar) and print those lines with a newline-prefix and the others with a 
single-space-prefix.

There is probably some fancy shortcut for doing all of this in one line, but I 
don't know it. Yet...

Enjoy!

-- 
Bjørge Solli - Office:+47 55205847 cellph.:+47 91614343
Nansen Environmental and Remote Sensing Center - Bergen, Norway
http://www.nersc.no Reception: +47 55205800
Dept.: Mohn-Sverdrup Center for Global Ocean Studies 
       and Operational Oceanography

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to