Sponsored Content
Top Forums Shell Programming and Scripting Generate Regex numeric range with specific sub-ranges Post 302781803 by varu0612 on Sunday 17th of March 2013 07:05:15 PM
Old 03-17-2013
Quote:
Originally Posted by RudiC
alister's proposal assumes a fixed bucket size (in this case 100 ms per bucket), and a fixed number of buckets, 10. Your header does not (5ms, 5ms, 10ms, 8 x 10ms, 50 ms, 50 ms, infinity) and thus is incompatible with that nice, simple, and linear solution. You would need to explicitly pass the buckets to awk; then it also would be easy to both print the header and check "out of range".

EDIT: Chubler_XL just outpassed me; his proposal comes close to what I had in mind. He just doesn't put the 279 ms in the sample file into the right bin.

EDIT 2: massaging Chubler_XL's proposal slightly, this might be acceptable to the requestor:
Code:
awk -v buckets="5,10,20,30,40,50,60,70,80,90,100,150,200" '
         BEGIN                  {n=split(buckets,B,",");B[n+1]=">"B[n]};
         /^Response time/       {for(i=1;B[i]&&($3>B[i]);i++);v[i]++}
         END                    {for (i=1; i<=n+1; i++) printf "%3sms,", B[i]
                                 printf "\n"
                                 for (i=1; i<=n+1; i++) printf "%3d  ,", v[i]
                                 printf "\n"
                                }
        ' OFS=, file
  5ms, 10ms, 20ms, 30ms, 40ms, 50ms, 60ms, 70ms, 80ms, 90ms,100ms,150ms,200ms,>200ms,
  1  ,  0  ,  1  ,  0  ,  0  ,  0  ,  0  ,  0  ,  0  ,  0  ,  0  ,  1  ,  0  ,  1  ,

The problem with your/ Chubler_XL suggestion is that i'll have to defined the upper bucket and this is the main reason why i'm moving away from my current solution otherwise for a range of 0 - 1000 with an upper bucket limit of 10 ms will take me ages to define it.

Alister's solution is very simple and so i have to defined only 2 values.

With regards to the header - i only gave an example but as i said to keep the nice/ tidy solution, the header should be generated based ont he n/ s values.

Cheers
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

numeric range comparisons

I have two files.And a sort of matrix analysis. Both files have a string followed by two numbers: File 1: A 2 7 B 3 11 C 5 10 ...... File 2: X 1 10 Y 3 5 Z 5 9 What I'd like to do is for each set of numbers in the second file indicate if the first or second number (or both) in... (7 Replies)
Discussion started by: dcfargo
7 Replies

2. Shell Programming and Scripting

awk to match a numeric range specified by two columns

Hi Everyone, Here's a snippet of my data: File 1 = testRef2: A1BG - 13208 13284 AAA1 - 34758475 34873943 AAAS - 53701240 53715412File 2 = 42MLN.3.bedS2: 13208 13208 13360 13363 13484 13518 13518My awk script: awk 'NR == FNR{a=$1;next} {$1>=a}{$1<=a}{print... (5 Replies)
Discussion started by: heecha
5 Replies

3. Shell Programming and Scripting

Count occurences of a numeric string falling in a range

Dear all, I have numerous dat files (1.dat, 2.dat...) containing 500 numeric values each. I would like to count them, based on their range and obtain a histogram or a counter. INPUT: 1.dat 1.3 2.16 0.34 ...... 2.dat 1.54 0.94 3.13 ..... ... (3 Replies)
Discussion started by: chen.xiao.po
3 Replies

4. Programming

Perl : Numeric Range Pattern Matching

hi Experts just wondering if you can help me check a number between a specific range if i have an ip address , how can i say the valid number for ip between 1 to 254 something like this if ($ip ) =~ /.../ { } what the pattern i need to type thanks (3 Replies)
Discussion started by: doubando
3 Replies

5. Shell Programming and Scripting

Awk numeric range match only one digit?

Hello, I have a text file with lines that look like this: 1974 12 27 -0.72743 -1.0169 2 1.25029 1974 12 28 -0.4958 -0.72926 2 0.881839 1974 12 29 -0.26331 -0.53426 2 0.595623 1974 12 30 7.71432E-02 -0.71887 3 0.723001 1974 12 31 0.187789 -1.07114 3 1.08748 1975 1 1 0.349933 -1.02217... (2 Replies)
Discussion started by: meridionaljet
2 Replies

6. Shell Programming and Scripting

getting files between specific date ranges in solaris

hi ! how can i get files in a directory between certain date ranges ? say all files created/modified between Jan24 - Jan31 thanks (10 Replies)
Discussion started by: aliyesami
10 Replies

7. Shell Programming and Scripting

sed filtering lines by range fails 1-line-ranges

The following is part of a larger project and sed is (right now) a given. I am working on a recursive Korn shell function to "peel off" XML tags from a larger text. Just for context i will show the complete function (not working right now) here: function pGetXML { typeset chTag="$1" typeset... (5 Replies)
Discussion started by: bakunin
5 Replies

8. Shell Programming and Scripting

Zipping files by numeric name range

Hi there, Not being too up on bash shell programming at this point, could anyone throw me a bone about how to zip up a set of numerically-named files by range? For example, in a folder that contains files 1.pdf through 132000.pdf, I'd like to zip up just those files that are 50000.pdf and... (6 Replies)
Discussion started by: enwood
6 Replies

9. Shell Programming and Scripting

Regex to exclude numeric

Dear All, My regex is like below. Its says all the number in coloum is include. 11666 11777 11888 ^(?\: (0|11)(666|777|888))\\d+$ How to exclude all the numeric that not mentioned in above regex. Regards, (3 Replies)
Discussion started by: tpx99
3 Replies

10. UNIX for Beginners Questions & Answers

Cannot subset ranges from another range set

Ca21chr2_C_albicans_SC5314 2159343 2228327 Ca21chr2_C_albicans_SC5314 636587 638608 Ca21chr2_C_albicans_SC5314 5286 50509 Ca21chr2_C_albicans_SC5314 634021 636276 Ca21chr2_C_albicans_SC5314 1886545 1900975 Ca21chr2_C_albicans_SC5314 610758 613544... (9 Replies)
Discussion started by: cryptodice
9 Replies
install::TempContent::Objects::mod_perl-2.0.9::docs::apiUserRContributed)install::TempContent::Objects::mod_perl-2.0.9::docs::api::APR::Brigade(3)

NAME
APR::Brigade - Perl API for manipulating APR Bucket Brigades Synopsis use APR::Brigade (); $bb = APR::Brigade->new($r->pool, $c->bucket_alloc); $ba = $bb->bucket_alloc(); $pool = $bb->pool; $bb->insert_head($b); $bb->insert_tail($b); $b_first = $bb->first; $b_last = $bb->last; $b_prev = $bb->prev($b_last); $b_next = $bb->next($b); $bb2 = APR::Brigade->new($r->pool, $c->bucket_alloc); $bb1->concat($bb2); $len = $bb->flatten($data); $len = $bb2->flatten($data, $wanted); $len = $bb->length; $bb3 = $bb->split($b_last); last if $bb->is_empty(); $bb->cleanup(); $bb->destroy(); Description "APR::Brigade" allows you to create, manipulate and delete APR bucket brigades. API
"APR::Brigade" provides the following functions and/or methods: "cleanup" Empty out an entire bucket brigade: $bb->cleanup; obj: $bb ( "APR::Brigade object" ) The brigade to cleanup ret: no return value since: 2.0.00 This method destroys all of the buckets within the bucket brigade's bucket list. This is similar to "destroy()", except that it does not deregister the brigade's "pool()" cleanup function. Generally, you should use "destroy()". This function can be useful in situations where you have a single brigade that you wish to reuse many times by destroying all of the buckets in the brigade and putting new buckets into it later. "concat" Concatenate brigade $bb2 onto the end of brigade $bb1, leaving brigade $bb2 empty: $bb1->concat($bb2); obj: $bb1 ( "APR::Brigade object" ) The brigade to concatenate to. arg1: $bb2 ( "APR::Brigade object" ) The brigade to concatenate and empty afterwards. ret: no return value since: 2.0.00 "destroy" destroy an entire bucket brigade, includes all of the buckets within the bucket brigade's bucket list. $bb->destroy(); obj: $bb ( "APR::Brigade object" ) The bucket brigade to destroy. ret: no return value excpt: "APR::Error" since: 2.0.00 "is_empty" Test whether the bucket brigade is empty $ret = $bb->is_empty(); obj: $bb ( "APR::Brigade object" ) ret: $ret ( boolean ) since: 2.0.00 "first" Return the first bucket in a brigade $b_first = $bb->first; obj: $bb ( "APR::Brigade object" ) ret: $b_first ( "APR::Bucket object" ) The first bucket in the bucket brigade $bb. "undef" is returned if there are no buckets in $bb. since: 2.0.00 "flatten" Get the data from buckets in the bucket brigade as one string $len = $bb->flatten($buffer); $len = $bb->flatten($buffer, $wanted); obj: $bb ( "APR::Brigade object" ) arg1: $buffer ( SCALAR ) The buffer to fill. All previous data will be lost. opt arg2: $wanted ( number ) If no argument is passed then all data will be returned. If $wanted is specified -- that number or less bytes will be returned. ret: $len ( number ) How many bytes were actually read. $buffer gets populated with the string that is read. It will contain an empty string if there was nothing to read. since: 2.0.00 excpt: "APR::Error" "insert_head" Insert a list of buckets at the front of a brigade $bb->insert_head($b); obj: $bb ( "APR::Brigade object" ) Brigade to insert into arg1: $b ( "APR::Bucket object" ) the bucket to insert. More buckets could be attached to that bucket. ret: no return value since: 2.0.00 "insert_tail" Insert a list of buckets at the end of a brigade $bb->insert_tail($b); obj: $bb ( "APR::Brigade object" ) Brigade to insert into arg1: $b ( "APR::Bucket object" ) the bucket to insert. More buckets could be attached to that bucket. ret: no return value since: 2.0.00 "last" Return the last bucket in the brigade $b_last = $bb->last; obj: $bb ( "APR::Brigade object" ) ret: $b_last ( "APR::Bucket object" ) The last bucket in the bucket brigade $bb. "undef" is returned if there are no buckets in $bb. since: 2.0.00 "length" Return the total length of the data in the brigade (not the number of buckets) $len = $bb->length; obj: $bb ( "APR::Brigade object" ) ret: $len ( number ) since: 2.0.00 "new" my $nbb = APR::Brigade->new($p, $bucket_alloc); my $nbb = $bb->new($p, $bucket_alloc); obj: $bb ( "APR::Brigade object or class" ) arg1: $p ( "APR::Pool object" ) arg2: $bucket_alloc ( "APR::BucketAlloc object" ) ret: $nbb ( "APR::Brigade object" ) a newly created bucket brigade object since: 2.0.00 Example: Create a new bucket brigade, using the request object's pool: use Apache2::Connection (); use Apache2::RequestRec (); use APR::Brigade (); my $bb = APR::Brigade->new($r->pool, $r->connection->bucket_alloc); "bucket_alloc" Get the bucket allocator associated with this brigade. my $ba = $bb->bucket_alloc(); obj: $bb ( "APR::Brigade object or class" ) ret: $ba ( "APR::BucketAlloc object" ) since: 2.0.00 "next" Return the next bucket in a brigade $b_next = $bb->next($b); obj: $bb ( "APR::Brigade object" ) arg1: $b ( "APR::Bucket object" ) The bucket after which the next bucket $b_next is located ret: $b_next ( "APR::Bucket object" ) The next bucket after bucket $b. "undef" is returned if there is no next bucket (i.e. $b is the last bucket). since: 2.0.00 "pool" The pool the brigade is associated with. $pool = $bb->pool; obj: $bb ( "APR::Brigade object" ) ret: $pool ( "APR::Pool object" ) since: 2.0.00 The data is not allocated out of the pool, but a cleanup is registered with this pool. If the brigade is destroyed by some mechanism other than pool destruction, the destroying function is responsible for killing the registered cleanup. "prev" Return the previous bucket in the brigade $b_prev = $bb->prev($b); obj: $bb ( "APR::Brigade object" ) arg1: $b ( "APR::Bucket object" ) The bucket located after bucket $b_prev ret: $b_prev ( "APR::Bucket object" ) The bucket located before bucket $b. "undef" is returned if there is no previous bucket (i.e. $b is the first bucket). since: 2.0.00 "split" Split a bucket brigade into two, such that the given bucket is the first in the new bucket brigade. $bb2 = $bb->split($b); obj: $bb ( "APR::Brigade object" ) The brigade to split arg1: $b ( "APR::Bucket object" ) The first bucket of the new brigade ret: $bb2 ( "APR::Brigade object" ) The new brigade. since: 2.0.00 This function is useful when a filter wants to pass only the initial part of a brigade to the next filter. Example: Create a bucket brigade with three buckets, and split it into two brigade such that the second brigade will have the last two buckets. my $bb1 = APR::Brigade->new($r->pool, $c->bucket_alloc); my $ba = $c->bucket_alloc(); $bb1->insert_tail(APR::Bucket->new($ba, "1")); $bb1->insert_tail(APR::Bucket->new($ba, "2")); $bb1->insert_tail(APR::Bucket->new($ba, "3")); $bb1 now contains buckets "1", "2", "3". Now do the split at the second bucket: my $b = $bb1->first; # 1 $b = $bb1->next($b); # 2 my $bb2 = $bb1->split($b); Now $bb1 contains bucket "1". $bb2 contains buckets: "2", "3" See Also mod_perl 2.0 documentation. Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. Authors The mod_perl development team and numerous contributors. perl v5.18.2 2015-install::TempContent::Objects::mod_perl-2.0.9::docs::api::APR::Brigade(3)
All times are GMT -4. The time now is 11:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy