grep -m

Jump to First Reply
Posted:
in Genius Bar edited January 2014
In Mac OS X, I see that -m is not a supported option of grep. It is supported in cygwin. Is this a cygwin specific feature or does Mac OS X just not support it? Is there anything else I can use in its stead?

Comments

  • Reply 1 of 6
    kickahakickaha Posts: 8,760member
    Well what is it supposed to *do*?
     0Likes 0Dislikes 0Informatives
  • Reply 2 of 6
    mcqmcq Posts: 1,543member
    Quote:

    Originally posted by Kickaha

    Well what is it supposed to *do*?



    Looking at my cygwin install:

    -m NUM, --max-count=NUM

    Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. This enables a calling process to resume a search. When grep stops after NUM matching lines, it outputs any trailing context lines. When the -c or --count option is also used, grep does not output a count greater than NUM. When the -v or --invert-match option is also used, grep stops after outputting NUM non-matching lines.



    Haven't used grep enough to comment on it.
     0Likes 0Dislikes 0Informatives
  • Reply 3 of 6
    kickahakickaha Posts: 8,760member
    Finding no such equivalent with the default grep, sorry. :/
     0Likes 0Dislikes 0Informatives
  • Reply 4 of 6
    I found a solution to my problem.



    I can't use



    grep -m 1 <string> <file>



    but I can use



    grep <string> <file> | head -n 1
     0Likes 0Dislikes 0Informatives
  • Reply 5 of 6
    fahlmanfahlman Posts: 742member
    Quote:

    Originally posted by MCQ

    Looking at my cygwin install:

    -m NUM, --max-count=NUM

    Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. This enables a calling process to resume a search. When grep stops after NUM matching lines, it outputs any trailing context lines. When the -c or --count option is also used, grep does not output a count greater than NUM. When the -v or --invert-match option is also used, grep stops after outputting NUM non-matching lines.



    Haven't used grep enough to comment on it.








    I were half as knowledgable as you I'd be a member of Mensa.
     0Likes 0Dislikes 0Informatives
  • Reply 6 of 6
    mcqmcq Posts: 1,543member
    Quote:

    Originally posted by rogue master

    I found a solution to my problem.



    I can't use



    grep -m 1 <string> <file>



    but I can use



    grep <string> <file> | head -n 1




    Yeah, that would work.



    Fahlman: Nice of you to say That was just copied from the man pages for grep though. There are many people on these forums more knowledgeable than me. Like Kickaha.
     0Likes 0Dislikes 0Informatives
Sign In or Register to comment.