[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

match across line using grep



I'm grepping a bunch of files each have a segment code that executes a SQL.
My problem is that the query spans across several lines and I can't
seem to make grep honor (?s) for that. Here's an example:

grep --E 'select.*from.*;' .

so that matches the following fine:

select * from mytable where id=1;

however, it does not match the following:

select * from mytable where id=1
and name='foo'";
I tried to use -z parameter for grep, which the manual says would make grep not treating \n as line terminator. But it doesn't work neither. A simple test shows I might have misunderstood the use of -z:

$ printf 'a\nb' | grep -zo a.*b

(The above should output something /if/ -z would make egrep not consider \n as string terminator. But it has produced no output)



Reply to: