cc: [email protected]
Subject: Re: [ast-developers] [RFE] read until content matches pattern?
--------


> The read command has "-d delim" to read until delimiter delim. I like
> to have a new option "-P pattern" read until the content matches the
> pattern "pattern" or until EOF. Currently I can do this only by
> reading the input stream one character at the time, then concatenate
> each character and match that against "pattern". This is an incredibly
> slow way compared to awk's line matching actions.
> 
> David
> 

If you are reading from a file, then you can use
        exec n<$ pattern
to seek to the next line that matches pattern where n is the file
number.

This can be following by a read to get the line containing
the pattern.

This does not work for non-seekable files.

For example to find and print all lines in a file that contain at least five 
consecutive  digits , you can do

        while   exec {n}<# *{5}(\d)* && read -r
        do      print -r -- "$REPLY"
        done    {n}< file

David Korn
[email protected]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to