Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

Just curious if there's a way I can show the output between two markers?

I was trying grep -r "<cron_expr>.*</run>" * but it doesn't seem to be returning as expected. Which is to say its not showing newline breaks?

So I guess the the real question is how can i find out what between two markers regardless of newline BS. I can't install on this system so no pcregrep =(

Maybe AWK?

(P.s. someone should make an AWK tag)

            <schedule><cron_expr>1 * * * *</cron_expr></schedule>
            <schedule><cron_expr>1 * * * *</cron_expr></schedule>

I just want to show whats on the <schedule> and <run> line(s if more than one, like above) anytime I see and what file they're in.

share|improve this question
grep and sed are both line-oriented. awk can use an arbitrary delimiter in place of newline, but still needs some kind of delimiter. What exactly are you looking for? You may be going about it the wrong way (for example, none of these tools is really appropriate for HTML/XML, and not ideal for JSON). – geekosaur May 4 '12 at 21:45
Yeah i'm searching through a bunch of config.xml's on our server to try and figure out when and what they're running in their private crontab, i'll post an example in a minute – ehime May 4 '12 at 22:07
up vote 2 down vote accepted

AWK script

AWK is probably the answer using the /start/,/stop/ pattern like this:

/<schedule>/,/<\/schedule>/ {
/<run>/,/<\/run>/ {

This will print everything in the schedule and run tags (including the tags) and will preserve new lines. Adapt it to print what you need. To run it:

cat myfile.txt | awk -f script.awk

XSLT style sheet

Here's an XSLT version that should do something very similar. Run it using xsltproc, which should be installed by default.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">

<xsl:template match="schedule">
    <xsl:value-of select="." />

<xsl:template match="run">
    <xsl:value-of select="." />

share|improve this answer
I can't install new things on our webserver so I need to work with the tools I have (grep sed/awk) =( Could I spit out all content between two instances of crontab? – ehime May 4 '12 at 22:21
How do you do the awk one without including the search tags? – rynop Sep 10 '12 at 13:09
AWK may not be the right tool if you want to exclude the search tags because it is line oriented so basically it matches a start line and an end line. If you want to exclude the delimiters, the XSLT version will be more adapted because XSLT understands the XML structure and will let you manipulate child nodes. In practice the XSLT example above strips out all XML tags and outputs the text only. – Bruno Girin Sep 10 '12 at 16:36

There are lots of ways to do what I think you want too do.

you could use sed

say I wanted to get the numbers in between lspci -nn

it spits out numbers like this


I would do this

lspci -nn| sed 's/.*\[\(.*\)\].*/\1/'

This is my first post here so I hope the escape character's are correct. But I am not sure what you are trying to do.

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.