search and replace a text in a file

Hi all,

I have a requirement where i have to search data between strings 'SELECT' and ';' and replace this text as "SELECT.....;" so that i can export this extracted string into a excel cell.

Please suggest on this.

If the SQL statement is on 1 line:

awk '/SELECT.*;$/{$0="\042" $0 "\042"}{print}' file

Regards

Thanks for quick reply..but,

My SQL statement is not on a single line. I am reading from a file say .txt which has many other statement apart from 'select'.

Say my file source.txt is like:

Update table
-----
----;
select --- from tablexx;

Delete from table1
----
---;

select from tablexy;

Then the output shud be like:

"select --- from tablexx;"
"select --- from tablexy;"

If you have the select statements on more lines (be aware of the upper/lower case of select):

awk '/select/{$0="\042" $0; f=1}f && /;$/{$0=$0 "\042";f=0}{print}' file

It is giving me syntax error...:frowning:

awk: syntax error near line 1
awk: bailing out near line 1

Use nawk or /usr/xpg4/bin/awk on Solaris.