sorting - Use AWK to search for a string and then rearrange -


i monthly stats in below format, need smallest , largest each column, use awk table out of larger file using script

awk 'c-->3;/by day/{c=35; print}' file1.txt 

and output:

by day:

 separate user logon counts-(max sessions)-(external counts)-(lock actions):  2013/04/07 -      6    (   6)  (  37)  (   0)  2013/04/08 -    190    (  70)  (6528)  (  30)  2013/04/09 -    185    (  68)  (5986)  (  29)  2013/04/10 -    213    (  85)  (5571)  (  36)  2013/04/11 -    189    (  82)  (5410)  (  35)  2013/04/12 -    165    (  69)  (5130)  (  25)  2013/04/13 -     16    (  15)  ( 662)  (   0)  2013/04/14 -     20    (  14)  (1016)  (   2)  2013/04/15 -    160    (  64)  (6770)  (  39)  2013/04/16 -    205    (  96)  (5978)  (  25)  2013/04/17 -    197    (  83)  (5816)  (  37)  2013/04/18 -    167    (  78)  (5554)  (  38)  2013/04/19 -    152    (  71)  (5479)  (  29)  2013/04/20 -     18    (  10)  ( 578)  (   1)  2013/04/21 -     11    (   7)  (1018)  (   2)  2013/04/22 -    193    (  74)  (6931)  (  30)  2013/04/23 -    176    (  66)  (6184)  (  23)  2013/04/24 -    192    (  74)  (5891)  (  26)  2013/04/25 -    188    (  79)  (5575)  (  28)  2013/04/26 -    170    (  75)  (5513)  (  26)  2013/04/27 -     17    (  12)  ( 597)  (   0)  2013/04/28 -     17    (  10)  (1021)  (   0)  2013/04/29 -    193    (  79)  (6786)  (  38)  2013/04/30 -    217    (  87)  (6094)  (  36)  2013/05/01 -    185    (  82)  (5706)  (  32)  2013/05/02 -    188    (  76)  (5602)  (  29)  2013/05/03 -    167    (  63)  (5149)  (  21)  2013/05/04 -     22    (  14)  ( 634)  (   1)  2013/05/05 -     21    (  14)  ( 728)  (   1)  2013/05/06 -      2    (   8)  (  46)  (   0) 

can edit awk script sort set column , display sorted column , first column?

the correct way print line containing "by day" , subsequent 35 lines is:

awk '/by day/{c=36} c&&c--' file1.txt 

now, post representative input (and no, not need 35 lines - make 5 or less) , expected output input , can take @ want next.

i see comment want print 3 lines before "by day" too. on it's own be:

awk ' /by day/{     (i=0;i<3;i++) {         j=(nr+i)%3         if (j in buf) {             print buf[j]         }     } } { buf[nr%3]=$0 } ' file 

so can combine as:

awk -v pre=3 -v post=35 ' /by day/{     (i=0;i<pre;i++) {         j = (nr+i) % pre         if (j in buf) {             print buf[j]         }     }     c = post + 1 } { buf[nr%pre]=$0 } c&&c-- ' file 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -