Display the output of a command from the first line until the first instance of a regular expression.

2010-01-04 209 words 1 min read

\"Screenshot
Image via Wikipedia

| perl -n -e 'print "$_" if 1 … /«a class="zem_slink freebase/en/regular_expression" title="Regular expression" rel="wikipedia" href="http://en.wikipedia.org/wiki/Regular_expression">regex>/;# This <a class="zem_slink freebase/en/command_line_interface" title="Command-line interface" rel="wikipedia" href="http://en.wikipedia.org/wiki/Command-line_interface">command line will display the output of , from the first line of output, until the first time it sees a <a class="zem_slink freebase/en/pattern_matching" title="Pattern matching" rel="wikipedia" href="http://en.wikipedia.org/wiki/Pattern_matching">pattern matching .

You could specify the regex pattern /^$/ to look for the first blank line,

or /^foobar/ to look for the first line that starts with the word foobar.

  • <a href="http://www.commandlinefu.com/commands/view/4405/display-the-output-of-a-command-from-the-first-line-until-the-first-instance-of-a-regular-expression.">View this command to comment, vote or add to favourites
  • <a href="http://feeds2.feedburner.com/commands/by/vargasmas">View all commands by <a href="http://feeds2.feedburner.com/commands/by/vargasmas">vargasmas

by David Winterbottom (<a href="http://codeinthehole.com">codeinthehole.com)

<a href="http://feedads.g.doubleclick.net/~a/Pek-GBh2_gauYh4DZ2deMo6igFU/0/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~a/Pek-GBh2_gauYh4DZ2deMo6igFU/0/di" border="0" alt="" align="bottom" />
<a href="http://feedads.g.doubleclick.net/~a/Pek-GBh2_gauYh4DZ2deMo6igFU/1/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~a/Pek-GBh2_gauYh4DZ2deMo6igFU/1/di" border="0" alt="" align="bottom" />

<img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~r/Command-line-fu/~4/Ie99mgx_Pfw" border="0" alt="" width="1" height="1" align="bottom" />

URL: <a href="http://feedproxy.google.com/~r/Command-line-fu/~3/Ie99mgx_Pfw/display-the-output-of-a-command-from-the-first-line-until-the-first-instance-of-a-regular-expression.">http://feedproxy.google.com/~r/Command-line-fu/~3/Ie99mgx_Pfw/display-the-output-of-a-command-from-the-first-line-until-the-first-instance-of-a-regular-expression.

There are couple of other ways you can do so, like using <a class="zem_slink freebase/en/sed" title="Sed" rel="wikipedia" href="http://en.wikipedia.org/wiki/Sed">sed, awk.

** |sed –quiet &#8217;/svn_/,$ !p&#8217;**<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://www.geekology.co.za/blog/2009/10/using-regular-expressions-part-2-of-4-regex-in-php/">Using Regular Expressions – Part 2 of 4 – Regex in PHP (geekology.co.za) <li class="zemanta-article-ul-li"><a href="http://ianloic.com/2009/06/05/implementing-text-pattern-matching-languages-in-llvm/">Implementing text pattern matching languages in LLVM (ianloic.com) <div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/13a6a746-2174-4fbd-a2fd-5e14f610ce9c/"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b40.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it