Re: User command to generate a formatted random number?
- From: "composlinuxmisc" <altcomphardware@xxxxxxxxxxx>
- Date: 30 Aug 2006 03:15:29 -0700
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.
.
- Follow-Ups:
- Re: User command to generate a formatted random number?
- From: Giovanni
- Re: User command to generate a formatted random number?
- References:
- User command to generate a formatted random number?
- From: Tom Hardy
- Re: User command to generate a formatted random number?
- From: composlinuxmisc
- Re: User command to generate a formatted random number?
- From: John-Paul Stewart
- User command to generate a formatted random number?
- Prev by Date: Re: alias/script to access Google archives? (was Re: A question about windoze trolls)
- Next by Date: Re: Some bash questions :-)
- Previous by thread: Re: User command to generate a formatted random number?
- Next by thread: Re: User command to generate a formatted random number?
- Index(es):
Relevant Pages
|
Loading