Re: User command to generate a formatted random number?




John-Paul Stewart wrote:
composlinuxmisc wrote:
Tom Hardy wrote:
I would like to be able generate a random number of specified size and
format on demand, suitable for cutting and pasting in email, e.g., a 32
bit hexadecimal string such as 1A3F238D.

You could try "date +%N".
Or:
date +%N | sed -e 's/000$//' -e 's/^0//'
Which strips the leading/traling zeros, according to:
http://www.tldp.org/LDP/abs/html/timedate.html

As a Linux rookie, I completely don't understand the bit after the
pipe, and would appreciate any quick & dirty explanations :-)

For more info about sed, see it's man page. It's one of the most useful
utilities available, IMHO.

The relevant bit here is its 's/a/b/' operator. The 's' is for
substitute, and it will substitute all occurrences of 'a' with 'b'. In
this case, there are two substitutions happening, both of which have
empty strings for 'b' (effectively causing sed to delete string 'a').

The first pattern is '000$' where the zeros mean literal zeros and $
means "end of the line" so it deletes three trailing zeros. In the
second substitution the '^' means "start of the line" so it deletes a
single zero at the start of a line.

Thanks John.

Your input was helpful and gave me a quick if basic understanding of
seb's syntax.

I really wish the man pages would include examples.

One line in /cat/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm
3dnowext 3dnow

cat /proc/cpuinfo | grep flags | sed -e s/se/TEST/
flags : fpu vme de pTEST tsc msr pae mce cx8 apic sep mtrr
pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm
3dnowext 3dnow

sed seems to replace the first instance of "se" here and not all of
them. (Sort of like :%s/a/b in vi).

Doing this:
cat /proc/cpuinfo | grep flags | sed -e s/se/TEST/ | sed -e s/se/TEST/

Causes it to replace the first two instances. A third time makes no
difference.

Sorry about the double post btw.

.



Relevant Pages

  • Re: User command to generate a formatted random number?
    ... Which strips the leading/traling zeros, ... The 's' is for substitute, and it will substitute all occurrences of 'a' with 'b'. ... In this case, there are two substitutions happening, both of which have empty strings for 'b'. ... The first pattern is '000$' where the zeros mean literal zeros and $ means "end of the line" so it deletes three trailing zeros. ...
    (comp.os.linux.misc)
  • Re: Pseudorandom Hashing
    ... Tim Wescott wrote: ... > getting a long string of zeros, a message is run through a CRC ... is the length of the pattern. ...
    (sci.electronics.design)
  • Re: Need help splitting up a fields data
    ... The easy way to parse out that kind of address is to extract what you know, and then remove it from the string, until the unknown part is left. ... So extract the zip code with RightWords, then Substitute out the string in the Zip field in the original field. ... Put that in the state field, then Substitute it out in the original field. ...
    (comp.databases.filemaker)
  • Re: Fomat cells for IP address including leading Zeros
    ... convert them to Remedy Format (with Leading Zeros where necessary.) I ... Function FormatURL(URL As String) As String ... If UBound3 Then Exit Function 'not a valid URL ...
    (microsoft.public.excel.worksheet.functions)
  • Re: I NEED macro for Combinations , Permutations or Arrangements ?
    ... I finally understand what you're trying to do, thanks to Dana. ... Start with a string of fifteen zeros followed by thirty ones; ... Any time you create a string with fifteen zeros and thirty ones, ... Or arrangements? ...
    (microsoft.public.excel.programming)

Loading