Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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'm wanting to find the results of a multi-line regular expression in linux. I tried grep, but like most linux utilities it's line based.

Is there something similar that allows me to search across multiple lines and simply output the matches?

Not perl, awk etc, unless I can give it a regex directly.

The problem

I've done svn propget --recursive on my subversion repositories and now want to extract all trunk entries, which would require a regex of the form ^http[^ ]trunk.$$ (where it starts at "http" at the start of the line, and finishes at an empty line.

share|improve this question

migrated from serverfault.com Aug 9 '11 at 6:10

This question came from our site for system and network administrators.

In a word: Perl – John Gardeniers Aug 9 '11 at 6:08
There are actually lots of tools that can do this. Can you be more specific about what the data looks like and what your search(es) are going to look like? – Caleb Aug 9 '11 at 17:44
@cyberx86: Thanks - do you want to answer it and get some more rep? – Stephen Aug 9 '11 at 21:25
up vote 3 down vote accepted

I don't know offhand the exact format you're trying to parse. If the http is always at the beginning of a paragraph (where paragraphs are separated by one or more blank line), you can invoke awk in paragraph mode (each paragraph is one record) and print records that begin with http. Perl has a similar mode.

awk -vRS= '/^http[^ ]/'
perl -000 -ne 'print if /^http[^ ]/'

If there isn't always a blank line before http, you can start printing when you see http and stop at a blank line. For example:

awk '/^http[^ ]/, /^$/'
perl -ne 'print if /^http[^ ]/../^$/'
share|improve this answer

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.