Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

Otherwise, this prints filenames and update statements:

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

-- from

(untested - caveat emptor)

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

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

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.