Results 1 to 10 of 10

Thread: egrep flag question

  1. #1
    Join Date
    Feb 2011
    Location
    127.0.0.1
    Posts
    472

    Default egrep flag question

    Hi,

    I found HERE some useful tip on generating a password using egrep and /dev/urandom. However, I don't know about the "1" flag in "-ioam1":
    Code:
    egrep -ioam1 '[a-z0-9]{8}' /dev/urandom
    I looked over the Internet, maybe I didn't look where I had to. I found what "ioam" flags stand for, but there wasn't anything about the "1" flag.
    Reliable + rider = RiDeR PlUs
    ...if you find this helpful, click on the star below...
    +-+ +-+
    |r| |+|
    +-+ +-+

  2. #2

    Default Re: egrep flag question

    It's the number argument to the '-m' which is in the manpage.


    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below...

  3. #3
    Join Date
    Feb 2011
    Location
    127.0.0.1
    Posts
    472

    Default Re: egrep flag question

    Quote Originally Posted by ab View Post
    It's the number argument to the '-m' which is in the manpage.


    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below...
    Thanks, ab. I checked the man of egrep again :
    Code:
    -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.
    So NUM was to be replaced with an actual number...didn't see that coming, good to know.
    Reliable + rider = RiDeR PlUs
    ...if you find this helpful, click on the star below...
    +-+ +-+
    |r| |+|
    +-+ +-+

  4. #4

    Default Re: egrep flag question

    Just to be completely clear, I did not know what it meant off the top of
    my head and have only used it once or twice in my life. I found this by
    removing the unknown option from the command and then hoping to see a
    difference in the output from which I could infer the option's purpose.
    Since instead I had an error message, I was led back to '-m'. I share
    this in case it helps in troubleshooting other flags in the future.

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below...

  5. #5

    Default Re: egrep flag question

    Just for a bit more explanation, this particular method of generating a
    random password does so by waiting for eight consecutive characters
    matching the regex specified (alphanumeric stuff basically) which happens
    pretty regularly and quickly, but if you increase the integer to something
    like 10 or higher you'll quickly see limits in the usability of this
    method to generate a long password unless you call it (the command)
    repeatedly. A way that I've found recently that seems to work
    more-reliably follows (for a 64-character password; adjust the last
    integer appropriately for other lengths):

    Code:
    --------------------
    tr -dc '!@#$%^&*()_+-=_A-Z-a-z-0-9' </dev/urandom | head -c${1:-64}
    --------------------

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below...

  6. #6
    Join Date
    Feb 2011
    Location
    127.0.0.1
    Posts
    472

    Default Re: egrep flag question

    Quote Originally Posted by ab View Post
    Just for a bit more explanation, this particular method of generating a
    random password does so by waiting for eight consecutive characters
    matching the regex specified (alphanumeric stuff basically) which happens
    pretty regularly and quickly, but if you increase the integer to something
    like 10 or higher you'll quickly see limits in the usability of this
    method to generate a long password unless you call it (the command)
    repeatedly. A way that I've found recently that seems to work
    more-reliably follows (for a 64-character password; adjust the last
    integer appropriately for other lengths):

    Code:
    --------------------
    tr -dc '!@#$%^&*()_+-=_A-Z-a-z-0-9' </dev/urandom | head -c${1:-64}
    --------------------

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below...
    I'd appreciate if you could explain what that does...there are many symbols in there and it could be difficult to understand for someone who doesn't know command line. And the order of operations is also important: you've specified a redirection symbol ("<") and a pipe ("|") - which one is parsed first?
    Reliable + rider = RiDeR PlUs
    ...if you find this helpful, click on the star below...
    +-+ +-+
    |r| |+|
    +-+ +-+

  7. #7

    Default Re: egrep flag question

    After reading a bit in the manpage I believe what it does is takes a list
    of characters as input (the stuff in single-quotes), finds the complement
    ('-c', so all of the other possible characters) and deletes those other
    characters (the complement) when they show up (-d). That output is piped
    to head which sees all of this from 'tr' as a big stream of data, because
    everything going into 'tr' is a big stream of data from /dev/urandom, and
    head then watches for sixty-four characters at which point it exits.

    Regarding stdin vs. stdout, all file descriptors exist at the same time so
    they all apply to a process at once. We feel like STDIN happens first
    because input usually comes before output, but it's just a broke in how we
    work that causes that misunderstanding. Every program in *nix always has
    three file descriptors defined: 0 (STDIN), 1 (STDOUT), and 2 (STDERR), and
    most have more. What goes into STDIN, or what comes out of STDOUT and
    STDERR, is up to the shell calling the program or the program itself, but
    they're always there. While the order matters a little bit around the
    operators, the placement of the operators doesn't matter as much as we
    think. For example, you could rework this to have the redirect to STDIN
    before the tr command itself. Go ahead, give it a shot.

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below...

  8. #8

    Default Re: egrep flag question

    riderplus wrote:
    > ab;2592793 Wrote:
    >> Code:
    >> --------------------
    >> tr -dc '!@#$%^&*()_+-=_A-Z-a-z-0-9' </dev/urandom | head -c${1:-64}
    >> --------------------

    >
    > I'd appreciate if you could explain what that does...there are many
    > symbols in there and it could be difficult to understand for someone who
    > doesn't know command line.


    In general, it's better if YOU make an attempt to understand it first
    and then post either specific questions about points you don't
    understand, or post your understanding and ask for confirmation. That
    way, you learn something, and you don't waste other peoples time.

    > And the order of operations is also
    > important: you've specified a redirection symbol ("<") and a pipe ("|")
    > - which one is parsed first?


    As ab explained, the order isn't important.

  9. #9
    Join Date
    Feb 2011
    Location
    127.0.0.1
    Posts
    472

    Default Re: egrep flag question

    Quote Originally Posted by djh-novell View Post
    In general, it's better if YOU make an attempt to understand it first
    and then post either specific questions about points you don't
    understand, or post your understanding and ask for confirmation. That
    way, you learn something, and you don't waste other peoples time.

    That's definitely my choice...firstly. Then, I understood what it was about, I asked ab to answer for others who might see this post, since he's more experienced than myself. Third, I'm not wasting anyone's time, I didn't press ab to answer at all, it was his choice to answer and give me further details, even an assignment.

    Quote Originally Posted by djh-novell View Post
    > And the order of operations is also
    > important: you've specified a redirection symbol ("<") and a pipe ("|")
    > - which one is parsed first?


    As ab explained, the order isn't important.
    ab didn't say that the order isn't important. In fact, in Linux the order in which symbols are parsed is essential. He said something else and I understood his point.
    Reliable + rider = RiDeR PlUs
    ...if you find this helpful, click on the star below...
    +-+ +-+
    |r| |+|
    +-+ +-+

  10. #10
    Join Date
    Feb 2011
    Location
    127.0.0.1
    Posts
    472

    Default Re: egrep flag question

    Quote Originally Posted by ab View Post
    After reading a bit in the manpage I believe what it does is takes a list
    of characters as input (the stuff in single-quotes), finds the complement
    ('-c', so all of the other possible characters) and deletes those other
    characters (the complement) when they show up (-d). That output is piped
    to head which sees all of this from 'tr' as a big stream of data, because
    everything going into 'tr' is a big stream of data from /dev/urandom, and
    head then watches for sixty-four characters at which point it exits.

    Regarding stdin vs. stdout, all file descriptors exist at the same time so
    they all apply to a process at once. We feel like STDIN happens first
    because input usually comes before output, but it's just a broke in how we
    work that causes that misunderstanding. Every program in *nix always has
    three file descriptors defined: 0 (STDIN), 1 (STDOUT), and 2 (STDERR), and
    most have more. What goes into STDIN, or what comes out of STDOUT and
    STDERR, is up to the shell calling the program or the program itself, but
    they're always there. While the order matters a little bit around the
    operators, the placement of the operators doesn't matter as much as we
    think. For example, you could rework this to have the redirect to STDIN
    before the tr command itself. Go ahead, give it a shot.

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below...
    I guess this is what you meant:
    Code:
    < /dev/urandom tr -dc '!@#$%^&*()_+-=_A-Z-a-z-0-9' | head -c${1:-64}
    Thank you for this assignment and for taking your time to provide those who read this post with so many details!
    Reliable + rider = RiDeR PlUs
    ...if you find this helpful, click on the star below...
    +-+ +-+
    |r| |+|
    +-+ +-+

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •