Loading ...
Sorry, an error occurred while loading the content.

Re:regexp needed

Expand Messages
  • daymobrew
    ... = 0xBF : RRQ ... (in.tftpd) ... 192.40.54.42 and what ... As you don t say if all the lines will have exactly the same data or whether you only wish to
    Message 1 of 2 , Apr 26, 2002
    • 0 Attachment
      --- In perl-beginner@y..., Jorge Goncalvez <goncal11@c...> wrote:
      > HI, I have a file like this:
      >
      > ....
      > 1015322638: in.tftpd : Win32 Process Id = 0xBF : Cygwin Process Id
      = 0xBF : RRQ
      > from 192.40.54.42 filename /bootp/linux/4.0/alize/initrd.img
      (in.tftpd)
      > .....
      >
      > And I wanted to match what is between from and filename ie
      192.40.54.42 and what
      > comes after filemane ie /bootp/linux/4.0/alize/initrd.img
      > without (in.tftpd)
      >
      > How can I do thanks to a regexp.
      > Thanks.

      As you don't say if all the lines will have exactly the same data or
      whether you only wish to match one line in the whole file...

      Maybe split on the colons:
      $Line = '1015322638: in.tftpd : ..etc.. (in.tftpd)';
      my @SplitLine = split( /\s*:/s*/, $Line;

      # $SplitLine[4] = 'RRQ ..etc.. (in.tftpd)'
      # You can either split on spaces
      my $filename = ( split( /\s+/, $SplitLine[4] ) )[4];
      # or use a reg exp.
      $SplitLine[4] =~ /^RRQ from [\d|\.]+? filename (.*?) \(in/;
      $filename = $1;

      I didn't check this code so there may be incorrect indices on the
      lists.
      And I'm sure others will have other/better solutions.
    Your message has been successfully submitted and would be delivered to recipients shortly.