in reply to Re: How to get a value from a file and save in another file
in thread How to get a value from a file and save in another file

Sorry for the cofusions and thanks for the help. I am new here I was not sure how to use the format yet. I am tring to output the first value with "LA" of each record.
The data file should be:
Record1: LA-1-00
Record2: CON-1-0
------------LA-2-01
Record3: LA-03-2
------------LA-03-02

I need the output like:
LA-1-00
LA-2-01
LA-03-2

  • Comment on Re^2: How to get a value from a file and save in another file

Replies are listed 'Best First'.
Re^3: How to get a value from a file and save in another file
by Jasper (Chaplain) on Apr 27, 2005 at 17:36 UTC
    perl -nl -e '/^Record/../LA/ && /(LA.+)/ && print $1' datafile ?

    I'm sure I'm doing much more work than necessary - but it's hot in the office.

      Shorter:
      perl -nle '/^\d/ .. /(LA.*)/ && print $1' datafile

      Safer:
      perl -nle '/^\d/ .. /^\d*\s+(LA.*)/ && print $1' datafile