Skip to main content
clarified GNU grep required for -m
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

Although it's an unconventional application of grep, you can do it in GNU grep using

grep -m1 "" file.txt

It works because the empty expression matches anything, while -m1 causes grep to exit after the first match

-m NUM, --max-count=NUM
       Stop reading a file after NUM matching lines.

Although it's an unconventional application of grep, you can do it using

grep -m1 "" file.txt

It works because the empty expression matches anything, while -m1 causes grep to exit after the first match

-m NUM, --max-count=NUM
       Stop reading a file after NUM matching lines.

Although it's an unconventional application of grep, you can do it in GNU grep using

grep -m1 "" file.txt

It works because the empty expression matches anything, while -m1 causes grep to exit after the first match

-m NUM, --max-count=NUM
       Stop reading a file after NUM matching lines.
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

Although it's an unconventional application of grep, you can do it using

grep -m1 "" file.txt

It works because the empty expression matches anything, while -m1 causes grep to exit after the first match

-m NUM, --max-count=NUM
       Stop reading a file after NUM matching lines.