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

\"Screenshot
Image via Wikipedia

| perl -n -e \'print \"$_\" if 1 ... /<regex>/;# This command line will display the output of , from the first line of output, until the first time it sees a 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.

by David Winterbottom (codeinthehole.com)

\"\"
\"\"

\"\"

URL: 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 sed, awk.

<command> |sed –quiet \’/svn_/,$ !p\’

\"Reblog

One thought on “Display the output of a command from the first line until the first instance of a regular expression.”

  1. Excellent and very thoughtful post! I really appreciate the time and effort you put in every single one of your posts, and finally decided to drop a comment on one of them! If you got some extra time on your hands and looking to improve your search engine rankings in the new Google Caffeine search results take a look at the Google Caffeine eBook…

    Anyways, good luck on your blog, and feel free to check out : Google Caffeine

    Thanks so much!

    All the best,
    Dino Vedo