in reply to How to extract lines starting with new names/words

For example, if the line begins with some comment, you will need another regexp

#!/usr/bin/perl use strict; use warnings; my $line ; while (<DATA>) { next unless /\A (\w+[.]\w+) \s+ (.+) \z/xms; print unless $line->{ $1 }++; }; __DATA__ # Log file 13/3/2008 MA01001A1A03.f1 760 5640111 ad1 MA01001A1A03.f1 760 42572233 ubq MA01001A1A04.f1 300 15232924 ubq MA01001A1A04.f1 300 145334669 DNA # MA01001A1B22.f1 580 77745475 ra MA01001A1B22.f1 580 30409730 ra MA01001A1A03.f1 760 5640111 foo MA01001A1A04.f1 300 15232924 bar # End of log
Output: MA01001A1A03.f1 760 5640111 ad1 MA01001A1A04.f1 300 15232924 ubq MA01001A1B22.f1 580 77745475 ra

hth,

PooLpi

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Update : for -> while, thanks johngg ;)

Replies are listed 'Best First'.
Re^2: How to extract lines starting with new names/words
by johngg (Canon) on Mar 13, 2008 at 10:43 UTC
    Your for (<DATA>) would be better written as while (<DATA>). Using for will have the effect of reading the entire file into memory rather than processing a line at a time as with while. Not a problem, perhaps, with small data sets but it's not a good habit to get into.

    Cheers,

    JohnGG

Re^2: How to extract lines starting with new names/words
by sm2004 (Acolyte) on Mar 13, 2008 at 23:42 UTC
    Thanks a lot. I could use the idea for another file I need to extract data. I'm new to perl and all your input helped a lot.