How Do I Grep First Occurrence in Unix?
Contents

How do you grep only one occurrence?

4 Answers

  1. Alternative syntax: grep -o “[^ ]*” – kenorb Oct 16 ’15 at 15:19.
  2. @kenorb which is a bit different actually (but will work in most cases). – peterph Oct 16 ’15 at 21:41.
  3. Use grep -oE … for regular expression – Morten Zilmer Jul 1 ’20 at 5:55.

How do I get my first grep match?

6 Answers. –m 1 means return the first match in any given file. But it will still continue to search in other files. Also, if there are two or more matched in the same line, all of them will be displayed.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest