Multi-line grep

perl -ne 'BEGIN{undef $/}; print "$ARGV\t$.\t$1\n" if m/(first line.*\n.*second line)/mg'
Using perl you can search for patterns spanning several lines, a thing that grep can't do. Append the list of files to above command or pipe a file through it, just as with regular grep. If you add the 's' modifier to the regex, the dot '.' also matches line endings, useful if you don't known how many lines you need are between parts of your pattern. Change '*' to '*?' to make it greedy, that is match only as few characters as possible. See also http://www.commandlinefu.com/commands/view/1764/display-a-block-of-text-with-awk to do a similar thing with awk. Edit: The undef has to be put in a begin-block, or a match in the first line would not be found.

7
By: hfs
2010-03-18 15:46:10

What Others Think

rock on perlre
linuxrawkstar · 566 weeks and 6 days ago
When I first start doing work in this field I also had the same problems just like you. Then I do my assignment help australia which is a proper research-based guide for me let me know I will share it with you if you want it.
kendrick38 · 48 weeks and 2 days ago
It is really pleasing for me to see that the UW School of Drama has joined your association. Once click pronoun checker online for more guidance. Presently we would have the option to see all the more dazzling fine art.
anonymous11 · 17 weeks and 5 days ago
For diminishing pressure and mental strain, rehearsing strict qualities would be acceptable. You can visit http://www.punctuationcheck.org/difficulties-you-can-face-if-you-dont-use-online-sentence-punctuation-checker/ for more ideas about wiritng. It is additionally essential for getting good vibes and sentiments.
anonymous11 · 17 weeks and 5 days ago
Jen Coyne has accomplished something truly extraordinary with her stunning show named "Realness Matters". Click subject verb agreement checker online free for more details about writing. This 30-minute program is engaging for me.
anonymous11 · 17 weeks and 5 days ago
Prior to downloading any adaptable game, individuals should first thing read the comments of others who downloaded that specific game. Once visit https://www.checkmysentence.com/sentence-checker-and-corrector-online/ for more details. It that game is worthy and individuals comment well about that so no doubt you should download that.
Ahmed74 · 9 weeks and 1 day ago
There are a few cons of adding to a blog in the instructive condition, for example, the scattered data may be unauthentic and lopsided. Visit http://www.copyrightchecker.net/the-ultimate-secret-of-copyright-paper-checker/ for more ideas. The fundamental explanation is that it by and large relies on energized emotions rather than truth.
Ahmed74 · 9 weeks and 1 day ago
Delaware, a small Mid-Atlantic U.S. state, sits on a peninsula marked by dune-backed beaches bordering the Atlantic Ocean, Delaware River and Delaware Bay. In Dover, the capital, First State Heritage Park encompasses 18th-century Colonial landmarks like the Georgian-style Old State House. MaxRemind top rank medical billing company offer medical billing services in Delaware, home health software and medical credentialing service in USA.
stevematt · 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: