Reputation: 524
I want to print only the paragraphs that begin with "select" and end with ";", but should contain "IN cccc" for example if I have the following code
select aaaa
bbbb
IN cccc
;
select dddd
eeeee
IN ffff
;
select rrrr
eeeee
IN cccc
;
the result would be like
select aaaa
bbbb
IN cccc
;
select rrrr
eeeee
IN cccc
;
so here's the awk I used awk '/^select*/,/^;/{if ($0 ~ /^IN cccc/) ; print}' inputfile
but I get as a result the entire content of my file
Upvotes: 1
Views: 198
Reputation: 14949
You can try this awk
:
awk 'BEGIN{ORS=RS=";"} /^[[:space:]]*select.*IN cccc/' file
Here,
ORS
- Output Record SeparatorRS
- Input Record SeparatorUpvotes: 4