How to catch a two word keyword which may contain a new line(may include spaces or tab) in it.
for example there is a file a.txt.
$more a.txt
create view
as
(select from
.........
..........
( select
....
(
select
......
..
select only no (((
number
( select
end
grep "([[:space:]]*select" a.txt
output:
(select from
( select
( select
but i want the 3rd select also to be caught(where there is a newline between "(" and "select" keyword)
i.e
(
select
what modification i should do in my grep command?
$ cat t
create view
as
(select from
.........
..........
( select
....
(
select
......
..
select only no (((
number
( select
end
This finds all of them:
$ grep "select" t
(select from
( select
select
select only no (((
( select
@spacebar Thanks for our reply. but i dont want all to be listed out. i want to catch a two word keyword(here it is "(" and "select" words) which may be seperated by a new line(may be searated by spaces or tab) . so "select only no (((" should not be there in the output.
@bipinajith
egrep "\([[:space:]]*select|select$" a.txt
in the second filter, you are assuming that it ends with "select" which is not the case always. The only goal is to catch a two word keyword(here it is "(" and "select" words) which may be seperated by a new line(may be searated by spaces or tab). for example b.txt .
more b.txt
(
select
....
(
select all
...
as
select
( select
@scrutinizer + sinari.. thanks for you reply. The sed command given by you is working for b.txt. But it will not work for all the cases to catch a two word keyword(here it is "(" and "select" words) which may be seperated by a new line(may be searated by spaces or tab) . for example
more c.txt
create view
as
(select from
.........
..........
( select
....
(
select
......
..
select only no (((
number
( select
.....
(
select all
.......
........
as (
select
........
end
the output should be:
(select from
( select
(
select
( select
(
select all
as (
select
/(.*select/!N if the line consists of a "(" followed by "select" then do not append the next line to the buffer..
//p repeat the previous match operation ( "(" followed by "select" ) and print the buffer if successful