Script to divide/expand first digit to show some numbers
Hello to everyone,
I have this complex problem and I don't how to do it. I'm not sure if awk could be a good choice to do it or could be easiest in bash or perl.
A kind of introduction would be:
- I have a digit, lets say 3.
- I can expand/spread out the digit 3 to cover all possible numbers that begin with 3 representing it with 2 digits and divide it in
10 parts like this:
30, 31, 32, 33, 34, 35, 36, 37, 38, 39. These 10 series are 3X, where X=0-9 and cover all values that begin with 3.
Well, what I really need is:
If have the digit 3 that covers all possible values that begin with 3 and I have some given numbers (one or more) that begin
with the same digit(in this example the digit is 3). I need to spread out the digit 3 up to the number of digits needed depending the
number of digits of the given numbers. Then add the text "GivenNum" once the 3 has been divided to show the given numbers.
Example:
Lets say that initial digit is 3 and given numbers are only two (304 and 3357):
Initial digit 3:
Numbers to show: 304, 3357
The output I'm looking for would be:
* As you can see for the first number 304, is needed to expand the series that begin with 3 up to 3 digits, since 304 has 3 digits.
* For the second number 3357, is needed to expand the series that begin with 3 up to 4 digits, since 3357 has 4 digits
* The series 31, 32, 34, 35, 36, 37, 38, 39 remain only represented up to 2 digits since the given numbers are not within of them.
Why does 304 expand to 300-309, but not 310-319 or 320-329? After skipping those two it does expand again -- to 330-334?
304 is only 3 digits length:
First digit=3
Second digit=0
Then I need to expand only the range that contains the given number, this is expand the 30X, where X=0-9. 31X and 32X are no expanded
since the goal is to show the output the most compact as possible and only expand as needed to show the given numbers (in this case 304, 3357).
Quote:
Originally Posted by Corona688
And the second one, why does it expand to 3350-3359 but not any other 4-digit ranges?
3357 is only 4 digits length:
First digit=3
Second digit=3
Third digit=5
Then I need to expand/open only the series 335X. And to expand 335X, first I need to expand the range 33X since 335X is inside 33X.
Quote:
Originally Posted by Corona688
And where do the 2-digit ranges come from?
The 2-digit ranges should be present if the given numbers are not inside them, since the range 3X is being expanded and the expansion should
contain all numbers that begin with 3 once is expanded. For example, if I only expand the series 30X and 335X without showing 38X, 39X, etc,
the output list won't be representing all numbers that begin with 3.
Thanks again.
Last edited by Ophiuchus; 10-14-2014 at 05:24 PM..
The 2-digit ranges should be present if the given numbers are not inside them, since the range 3X is being expanded and the expansion should contain all numbers that begin with 3 once is expanded.
Why does that matter when expanding a 4 digit number and not a 3 digit one?
Quote:
For example, if I only expand the series 30X and 335X without showing 38X, 39X, etc, the output list won't be representing all numbers that begin with 3.
The list will never represent all numbers that begin with 3. An exhaustive list will be infinite.
How can I test the AWK code? jeje for example for the example of my first post?
Quote:
Originally Posted by Corona688
Why does that matter when expanding a 4 digit number and not a 3 digit one? The list will
never represent all numbers that begin with 3. An exhaustive list will be infinite.
Never will be an infinite list. I generate these lists from time to time but manually and is time consuming.
Is not a thing that 3 or 4 digits, only that expand or not the range needed, for example if the given numbers were
35 and 3703 the list would be.
Thanks again.
Hello, I have an assignment that requires us to use sed only. The first part of the assignment says to use a sed script to print only the even lines, but if it is print, the number of that lines needs to be printed before the text.
ex:
2
line 2 text
4
line 4 text
6
line 6 text
... (3 Replies)
Hi,
I've been working on a few scripts and have been getting great info.
How, would I include in the below script, how I would let a user know that if they divide a SECOND number by zero, that they would get a divide by zero error? What's the easiest way of working this?
Cordially,
joe.
... (1 Reply)
Hi Unix Gurus,
I have a requirement to generate positive random 16 and 13 digit numbers.
Here is the script I have so far.....
number=$RANDOM$RANDOM$RANDOM$RANDOM;
let "number %= 10000000000000";
echo $number
But sometimes it is generating negative numbers and also 15 digit... (8 Replies)
Hi All,
I am stuck with this problem.
I have some 100000 (.dat) 1.dat, 2.dat,3.dat etc until 100000.dat files which look like this:
1.dat
1
2
3
4
0.99
4.54
All my files 1.dat until 100000.dat look the same but with different numbers.
I have to first add all the numbers in each... (1 Reply)
divide input values into specified number (-100 or -200) according to the key (a1 or a2 ....)
For ex: if we give -100 in the command line it would create 100 number intervals (1-100, 100-200, 200-300) untill it covers the value 300 in a1.
Note: It should work the same even with huge numbers... (3 Replies)
Folks,
Is there a simple way to replace one digit by two digit using sed.
Example,
mydigit1918_2006_8_8_lag1.csv should be
mydigit1918_2006_08_08_lag01.csv.
I tried this way, but doesn't work.
echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/'
Thank you, (5 Replies)
i need to divide this count by 2, what variable can i use in my script?
26 hcscprod_cpus_totals /2 = 13
13 hcncprod_cpus_totals /2= 6.5
541 ktazp_cpus_totals /2= 270.5
346 ktazd_cpus_totals /2=173
110 ktazi_cpus_totals /2=55
10 ktazq_cpus_totals /2=5 (2 Replies)