Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to find a paragraph is a list of files. For example an SQL statement which looks like:

upadte b_table
set number = 100014
where id in (
            select number_desc from t_table
            where id > 100);

How should I ignore enter/new lines?

I need to find/print a paragraph which starts with "update" and finishes with the first occurrence of ;

share|improve this question

3 Answers 3

grep is a bit tricky with newlines, but you could try something with awk:

awk '/update/,/;/' < filename.sql
share|improve this answer
How would you deal with a file containing multiple update statements? –  RedGrittyBrick Jun 2 '11 at 12:36
@RedGrittyBrick - The above statement should print all statements with the matching start and stop parts. I assume that's what is required. –  barryj Jun 2 '11 at 12:55

Inspired by barryj's concise awk solution:

perl -ne 'print if /update/../;/' *.sql

If the update statements are contained in (empty-line delimited) paragraphs:

perl -00 -ne 'print if /update.*?;/' *.sql

-- from http://uselessuseofcat.com/?p=381

Otherwise, this prints filenames and update statements:

perl -ne 'BEGIN{undef $/}; print "$ARGV\t$.\t$1\n" if m/(update.*?;)/mg' *.sql

-- from http://www.commandlinefu.com/commands/view/5087/multi-line-grep

(untested - caveat emptor)

share|improve this answer
ok - i did used grep with regexp like this: –  user84129 Jun 7 '11 at 5:05

I used grep like this:

grep -ihRP  '^(update|( )* update) .* [^;]*;'
share|improve this answer
using grep with perl engine other wise regexp not works "good" in bash and prints everything except ; after the word "update" or " update" until first appearance of ; –  user84129 Jun 7 '11 at 5:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.