Bash Shell Scripting
Crash Course
crowfly.net

<<   >>

Introduction

GNU_Tools

Example1

Example2

Execution_bit

Bang_bin_bash

Example3

The_dot

Example4

Example5

Example6

Example7

Example8

Background

Forking

Example9

Bash_profile

Pattern_match

Regex

Debug

Gory_details

References

<<   >>
Example 7

histogram

  sort $* | uniq -c | sort -rn

Usage might looks like this:

How many Titles are there for VHS and DVD?

  dlink@viddev1> export vd=/video/def
  dlink@viddev1> export vdata=/video/data
  dlink@viddev1> grep -i type $vd/title.def
  .ELEMENT TYPE      FORMAT  STRT STOP ITEM  CODES, VALUES and FLAG SETTINGS
  NeType   DIM       01   13-  13    14 M(VHS)OR L(DVD)   DuCFGS
  NeDVDtyp DIM       01  319- 319    DVD Type                       New TJH033105
  dlink@viddev1> cut -c13 $vdata/zum/title.fil| histogram
   100291 M
    87303 L
       10 J
        1 I
        1 D
        1  

What about Screen format?:

  dlink@viddev1> grep -i format $vd/title.def
  .ELEMENT TYPE      FORMAT  STRT STOP ITEM  CODES, VALUES and FLAG SETTINGS
  NeFormat DIM       02  193- 194    21 FORMAT            UpITDSC1  WS PS x .
  dlink@viddev1> cut -c193-194 $vdata/zum/title.fil| histogram
   172611 PS
    13039 WS
     1478 MU
      476 x 
        2   
        1 

And by genre?:

  dlink@viddev1> grep -i genre $vd/title.def
  NeGenre  DIM       03  121- 123    27 GENRE             UpITDSC2 DuC18
  NeGensub DIM       03  124- 126    33 CHILD GENRE       Via GENRE              .
  NeVSGen  DIM       01  267- 267    1-BYTE GENRE FROM VIDEOSCAN DATABASE
  dlink@viddev1> cut -c121-123 $vdata/zum/title.fil| histogram
    19656 936
    17366 933
    15858 850
    13522 927
    12734 935
    10880 914
     8482 926
     7975 902
     7703 945
     7691 940
     7095 901
     5658 969
     5281 943
     5059 944
     4337 948
     4294    
     3846 x  
     3719 946
     3279 900
     3234 937
     3128 942
     2850 100
     2025 8  
      677 947
      635  X 
      617 000
      591 200
      482 905
      443 300
      ...

Here is a histogram of all the words in the first paragraph of Moby Dick:

  dlink@viddev1> cat moby |tr ' ' '\n'| histogram | more
      10 the
       9 I
       7 and
       5 to
       5 a
       4 of
       4 my
       4 is
       4 in
       3 whenever
       3 me
       3 it
       3 -
       2 time
       2 or
       2 off
       2 nothing
       2 myself
       2 little
       2 get
       2 find
       2 as
       2 about
       1 years
       1 would
       1 world.
       1 With
       1 with
       1 Whenever
       1 way
       1 watery
       1 warehouses,
       1 very
       1 upper
       1 upon
       1 up
       1 towards
       1 throws
       1 thought
       1 This
       1 this.
       1 they
       1 There
       1 then,
       1 their
       1 that
       1 take
       1 sword;
       1 surprising
       1 such
       1 substitute
       1 strong
       1 street,
       1 stepping
       1 spleen,
       1 soul;
       1 soon
       1 Some
       1 some
       1 shore,
       1 ship.
       1 see
       1 sea
       1 same
       1 sail
       1 requires
       1 regulating
       1 rear
       1 quietly
       1 purse,
       1 principle
       1 prevent
       1 precisely
       1 pistol
       1 philosophical
       1 people's
       1 pausing
       1 particular
       1 part
       1 other,
       1 on
       1 ocean
       1 November
       1 no
       1 never
       1 nearly
       1 mouth;
       1 moral
       1 money
       1 mind
       1 methodically
       1 men
       1 meet;
       1 me.
       1 me,
       1 long
       1 knocking
       1 knew
       1 It
       1 it,
       1 Ishmael.
       1 involuntarily
       1 into
       1 interest
       1 If
       1 hypos
       1 how
       1 his
       1 himself
       1 high
       1 having
       1 have
       1 hats
       1 hand
       1 growing
       1 grim
       1 funeral
       1 from
       1 for
       1 flourish
       1 feelings
       1 every
       1 especially
       1 drizzly
       1 driving
       1 deliberately
       1 degree,
       1 damp,
       1 coffin
       1 circulation.
       1 cherish
       1 Cato
       1 can.
       1 Call
       1 but
       1 bringing
       1 before
       1 ball.
       1 an
       1 almost
       1 all
       1 ago
       1 account