Skip to main content
edited tags
Link
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k
deleted 6 characters in body
Source Link
Dhruv
  • 113
  • 5

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 and \W\w|\W should match any character. But the second command doesn't print the patterns that span multiple lines.

Can anyone tell why so?

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 and \W should match any character. But the second command doesn't print the patterns that span multiple lines.

Can anyone tell why so?

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?

edited body
Source Link
Dhruv
  • 113
  • 5

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 and \W should span all charactersmatch any character. But the second command doesn't print the patterns that span multiple lines.

Can anyone tell why so?

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 and \W should span all characters. But the second command doesn't print the patterns that span multiple lines.

Can anyone tell why so?

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 and \W should match any character. But the second command doesn't print the patterns that span multiple lines.

Can anyone tell why so?

Source Link
Dhruv
  • 113
  • 5
Loading