How do you grep 'select * from table_name' string from a script if the select * and from table_name are on 2 different lines ? like
select *
from table_name
Any help would be greatly appreciated !!!
Thanks
RDR
How do you grep 'select * from table_name' string from a script if the select * and from table_name are on 2 different lines ? like
select *
from table_name
Any help would be greatly appreciated !!!
Thanks
RDR
You can't grep across multiple lines.
Not sure if this helps but the following code will print out the required lines
sed '/select/,/table_name/!d' file1.txt
OR
sed '/select \*/,/from/!d' file1.txt
Hi.
Unlike grep, egrep, or fgrep, cgrep allows the matching of patterns,
delimiters, or trail_patterns that may span multiple lines of text
through the use of literal newline characters. The section, MULTI-LINE
MATCHING, explains this in more detail.
-- excerpt from man cgrep
available at:
cgrep | Download cgrep software for free at SourceForge.net
Best wishes ... cheers, drl
how about this?
echo "a
###select *
from table_name####
sein
select *
egeg
from table_name###" |awk -v RS='select \\*$\nfrom table_name' '{print RT}'
select *
from table_name