Display the output of a command from the first line until the first instance of a regular expression.
| 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 ’/svn_/,$ !p’ <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">
Related Articles:
- 2009/11/17 Calculations
- 2009/12/24 EncFS – Simple article to use Encrypted filesystem in Linux
- 2009/12/18 Display a block of text with delineated by a start pattern and an end pattern
- 2008/10/13 Scratch — Programming for kids