Removing Line numbers

Hi all,

I have a file consisting of lines in such a format: [sentence number (e.g. M1) and word[ I] separated by space and M1 EOS for fullstop (.) ]

e.g

M1  I
M1 have
M1 a 
M1 file
M1 consisting
M1 of
M1 lines
M1 in 
M1 such
M1 a
M1 format
M1 EOS
M2 This
M2 is 
M3 an
M3 example
M3 EOS

Now I want to get back to original format as:

I have a file consisting of lines in such a format.
This is an example.

I want to write a Perl script for this purpose. I have started the script as follows. But I don't know how to proceed further. Any help is appreciated to complete the script.

 open my $M_IN, "<:encoding(utf8)", "$ARGV[0]" or die "Can't open file $ARGV[0]: $!";
 while(my $my_input= <$M_IN>)
        {
                @m_input_text= split /\s+/, $my_input;
                
        }

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

perl -i -pe 's/^M. //g' file
$
$
$ cat data.txt
M1  I
M1 have
M1 a
M1 file
M1 consisting
M1 of
M1 lines
M1 in
M1 such
M1 a
M1 format
M1 EOS
M2 This
M2 is
M3 an
M3 example
M3 EOS
$
$ perl -ne '{chomp; s/^M\d[ ]+//g; s/[ ]*$//; $x .= " ".$_}
            END {$x =~ s/^ //; $x =~ s/ EOS[ ]*/.\n/g; print $x}' data.txt
I have a file consisting of lines in such a format.
This is an example.
$
$

tyler_durden

You can also accomplish this without perl

awk '/^M[0-9]+[ \t]+/&&$2!="EOS"{printf("%s ",$2)}$2=="EOS"{printf(".\n")}' data.txt| sed 's/ \.$/./'