Hi roof,
Why don't you think 000 and 029 just as valid as 3-digit random numbers as 100 and 999?
Assuming that characters two through four on every input line are spaces (which was not stated in the requirements, but is true in the given 2-line sample input) and you're using a recent bash, a 1993 or later ksh, or zsh, you could change your suggestion from:
to:
to change characters three through five to a 3-digit random number in the given sample input.
But, hhdzhu still hasn't given us a clear specification of what output is desired. (Specifying offsets 2 to 4 are to be changed is ambiguous since we haven't been told whether the 1st character on a line is offset 0 (as in bash and recent ksh ${variable:offset[:length]}) or offset 1 (as in awk substr(string, offset[, length])) and sample input and output that does' t match either of these.
And, since the input is "thousands of lines", it isn't obvious whether or not my awk suggestion would be slower or faster processing the desired file than the zsh (or ksh93 or bash) script you suggested (modified as shown above) inserted into a while read loop to process the entire file instead of just one line.
Hi roof,
Why don't you think 000 and 029 just as valid as 3-digit random numbers as 100 and 999?
I didn't say it isn't, but it might be. Some people consider a 3-digit number as one which is higher than 99 (and might be disappointed, if they get promised an hourly payment in the "range of a 3-digit-number" and end up getting payed US$ 002 per hour), and others are happy with a leading zero. The OP didn't say anything, and I gave my implementation as an example.
Quote:
Originally Posted by Don Cragun
And, since the input is "thousands of lines", it isn't obvious whether or not my awk suggestion would be slower or faster processing the desired file than the zsh (or ksh93 or bash) script you suggested.
To be honest, even for a couple of thousands of lines, speed difference should only matter if the same type of transformation is done many times in a loop. I gave zsh as an example, because I personally use either zsh or Ruby for this type of task (out of a habit), but bash, Perl, Python, awk etc. work of course equally well, and the OP did not have expressed a preference for a particular language.
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
Write a shell script that will take the sum of two random number?
Ex: Random n1 +Random n2 = result
i tries to write it but i had some dufficulties
... (3 Replies)
Hi All,
I have one file name called test.txt and its having numbers inside the file.I need to identified next available number with use of unix shell scipt and have to update next available number with use of unix shell script.
Example:-
cat test.txt
5001
5002
5003
5005
7000
7001
... (5 Replies)
Can I insert rows based on line numbers. Say If I need to insert 1 or more rows in a file from line number 10. Can I do that in UNIX
I have a file something like
A
B
C
D
E
F
After row C, I wanted to add 2 records as X and Y. I have the line number after C as my reference. Can I... (2 Replies)
Hi Can someone help me with this one?
I have string..
(PROC_PROC_ID == 12183) <--PID is dynamic
and i want to replace the PID number with whatever PID from
/opt/hpws/apache32_2/logs/httpd.pid file.
i'm having problem since the PID on the string is dynamic. It may be 2-5 digits or more.
... (5 Replies)
Hi,
I am having trouble with generating random numbers. can this be done with awk?
So I have a file that looks like this:
23 30
24 40
26 34
So column1 is start and column2 is end. I want to generate 3 random #'s between start and stop:
So the output will look like this:
... (9 Replies)
Hi Guys I have a script to find Ranomd numbers. But I want to make the file to produce more random. Could u guys help me plz.
In this Script I have the code that generates random in for loop and the range I have specified in my %chromlength
input and out put will be like this
chrno start end... (3 Replies)
Hello All,
I want to make a simple script which generate random number from 0 to 1000.
and simply display it.
Plz HELP!!!!!!
Regards,
Waqas Ahmed (2 Replies)
Is anyone know some scripts to generate random number without repetition using bash; for example generate 10 different random numbers.
Thanks (8 Replies)