Zary Necheva wrote:
>
> How can I extract the text before the first occurrence of dot (.) or
> single space from the first field.
>
> This is my file
>
> LB1571 5TH .W43 1993|text1|text1|
> FICT. V.12|text2|text2|
> FICT.|text3|text3|
> HQ806 .B35 1995|text4|text4|
> G530.T6B4941988Q|text5|text5|
> MPCD11 .B42 P27|text6|text6|
> .....
> C |textn|textn
>
> This is the output that I need
>
> LB1571|tex1|text1|
> FICT|text2|text2|
> FICT|text3|text3|
> HQ806|text4|text4|
> G530|text5|text5
> MPCD11|text6|text6
> .....
> C |textn|textn
Hi Zary.
It's not clear whether you need the trailing pipe character,
as your first four example output lines include it and the
remainder leave it out. But the program below should help.
Cheers,
Rob
use strict;
use warnings;
while (<DATA>) {
print "$1|$2\n" if /([^\s.]+) .*? \| (\S+) \s* $/x;
}
__DATA__
LB1571 5TH .W43 1993|text1|text1|
FICT. V.12|text2|text2|
FICT.|text3|text3|
HQ806 .B35 1995|text4|text4|
G530.T6B4941988Q|text5|text5|
MPCD11 .B42 P27|text6|text6|
**OUTPUT
LB1571|text1|text1|
FICT|text2|text2|
FICT|text3|text3|
HQ806|text4|text4|
G530|text5|text5|
MPCD11|text6|text6|
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>