I was trying to search for lines that start with create and end in ;. The match may span multiple lines. I was trying to use grep for that and after searching internet I found out how to do it.
The following query does it
grep -zioE 'create (\w|\W|\n)*?;' Day1.sql | less # Output create schema sigmoid_db; create table instructor( ID char(5), name varchar(20), dept_name varchar(20), salary numeric(8,2)); What I want to ask why wouldn't the same query without \n work? Like the following query should produce the same output
grep -zioE 'create (\w|\W)*?;' Day1.sql | less # Output create schema sigmoid_db; My reasoning is \w|\W should match any character. But the second command doesn't print the patterns that span multiple lines.
Can anyone tell why so?
*?for non-greedy*is a perl operator. Very fewgrepimplementations support it with-E.pcregrep -Mio '(?s)^\h*create .*?;'.grep (BSD grep, GNU compatible) 2.6.0-FreeBSD