0

So I have been using a command piped through curl (on GNU/Linux's grep utility) to generate a random password string for tightening security on some of my accounts.

curl -s https://www.grc.com/passwords.htm | grep -oP '[a-zA-Z0-9]{63}' | tail -n1 | cut -c1-63

I'm trying to make this command work on a Mac, and seeing as though Mac has the BSD General Utilities being a Unix base, the flags are different. I've referenced the grep man page for the BSD General commands utility, and came across a few flags that appeared they would work, but I can't get it to parse the page correctly. If someone can point me in the right direction, or let me know what I'm missing I would appreciate it.

I have a feeling it's right in front of my face.

The -e flag seemed like a righteous fit, but it is not working either.

-e pattern, --regexp=pattern Specify a pattern used during the search of the input: an input line is selected if it matches any of the specified patterns. This option is most useful when multiple -e options are used to specify multiple patterns, or when a pattern begins with a dash ('-').

0

-o (only print the matching part of the line) is the same on both BSD and GNU grep.
-P (use Perl-Compatible Regular Expressions, a.k.a. "PCRE") is specific to GNU grep.

Luckily, your example regular expression doesn't use any PCRE-specific syntax. But it doesn't conform to classic Unix RE syntax either. It needs "Extended" Regular Expressions (EREs). You can get that on BSD grep by adding -E or by calling egrep instead of grep.

curl -s https://www.grc.com/passwords.htm | grep -oE '[a-zA-Z0-9]{63}' | tail -n1 | cut -c1-63

If you have other REs that truly require PCRE, you can always install GNU grep (and, if you want, the vast majority of any of your other favorite open source software packages) via package managers such as Homebrew, MacPorts, or Fink.

  • Thank You very much for the reply, and it makes much sense. – shome_slice Jan 24 '16 at 4:08
  • @shome_slice If my solution worked for you, you can click the checkmark outline next to my answer to mark it as "accepted", so people know this question has been resolved. – Spiff Jan 25 '16 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.