Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: remove lines that do not match search pattern

by pme (Prior)
on Aug 03, 2015 at 14:12 UTC ( #1137257=note: print w/replies, xml ) Need Help??


in reply to remove lines that do not match search pattern

Hi jasonwolf,

You can do that in your Expect (http://expect.sourceforge.net/) script. Expect is a Tcl extension and Tcl (http://wiki.tcl.tk) has regexp: http://wiki.tcl.tk/986. Do you really need separate script to filter the log?

  • Comment on Re: remove lines that do not match search pattern

Replies are listed 'Best First'.
Re^2: remove lines that do not match search pattern
by jasonwolf (Sexton) on Aug 03, 2015 at 14:24 UTC

    Thanks for the suggestions as to using Expect. I will take a look at this

    Just for my own knowledge - what do I call what I am trying to do with 0-9|a-e:0-9|a-e?

      ... what do I call what I am trying to do with 0-9|a-e:0-9|a-e?

      Assuming you're actually working with  [0-9]|[a-e]:[0-9]|[a-e] (please use  <code> ... </code> tags in future; please see Writeup Formatting Tips, Markup in the Monastery), it can be explained as:

      c:\@Work\Perl\monks>perl -wMstrict -le "use YAPE::Regex::Explain; ;; my $rx = qr{ [0-9] | [a-e]:[0-9] | [a-e] }xms; print YAPE::Regex::Explain->new($rx)->explain; " The regular expression: (?msx-i: [0-9] | [a-e]:[0-9] | [a-e] ) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?msx-i: group, but do not capture (with ^ and $ matching start and end of line) (with . matching \n) (disregarding whitespace and comments) (case-sensitive): ---------------------------------------------------------------------- [0-9] any character of: '0' to '9' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- [a-e] any character of: 'a' to 'e' ---------------------------------------------------------------------- : ':' ---------------------------------------------------------------------- [0-9] any character of: '0' to '9' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- [a-e] any character of: 'a' to 'e' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
      See YAPE::Regex::Explain for regexes of Perl version 5.6 or before.


      Give a man a fish:  <%-(-(-(-<

      OT

      Filtering with Tcl/expect:

      #!/usr/bin/expect while {[gets stdin line] >= 0} { if {[regexp {([[:xdigit:]]{2}:?){6}} $line]} { puts $line } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1137257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2020-01-20 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?