home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / lang / awk / 5 < prev    next >
Encoding:
Text File  |  1993-01-21  |  1.7 KB  |  61 lines

  1. Newsgroups: alt.lang.awk
  2. Path: sparky!uunet!mcsun!julienas!jussieu!shiva.jussieu.fr!petit
  3. From: petit@lirac.ibp.fr (Pascal PETIT)
  4. Subject: Re: Counting
  5. In-Reply-To: etxalve@xmas.ericsson.se's message of Wed, 20 Jan 1993 08:43:26 GMT
  6. Message-ID: <PETIT.93Jan21181518@lirac.ibp.fr>
  7. Sender: news@jussieu.fr (Le Facteur)
  8. Nntp-Posting-Host: lirac.ibp.fr
  9. Organization: LITP, IBP, Universite Pierre et Marie Curie Paris 6, 4 place
  10.     Jussieu, 75252 PARIS CEDEX 05, France telephone : +33 (1) 44-27-61-99,
  11.     fax: +33 (1) 44-27-40-42
  12. References: <18JAN199317320021@pavo.concordia.ca> <1993Jan19.140510.24158@bnr.ca>
  13.     <etxalve.727519406@xmas>
  14. Date: Thu, 21 Jan 1993 17:15:18 GMT
  15. Lines: 44
  16.  
  17. In article <etxalve.727519406@xmas> etxalve@xmas.ericsson.se (Bengt Alverborg TM/SDB 34369 2670 ( tom -> 930301  )) writes:
  18.  
  19.    >>I have a test file that is seperated in to columns.  I would like to
  20.    >>increment a counter when the second column(TIME) is on the hour
  21.    >>(ex.  1:00--> i=1,   2:00 -->i=2...)
  22.            ^         ^    #         #
  23.  
  24.  
  25.  
  26.    #!/bin/awk -f
  27.    $2 ~ /[0-9]:00/ {count++}
  28.    END { printf "\n\nCount is:%d\n\n",count }
  29.  
  30.    And it will work perfectly for the second column (TIME) (hopefully)!
  31.  
  32.  
  33. it counts the number of lines. but to get the hour in an expression
  34. like this try : 
  35.  
  36. #!/bin/awk -f
  37.    $2 ~ /[0-9]:00/ {split($2,time,/:/);i = time[1];print i}
  38.  
  39. if the file is :
  40. adsfd 1:00
  41. dafhsldkj kdsflhlsd
  42. kjdahslka 34:00
  43.  
  44.  
  45. it will print :
  46. 1
  47. 34
  48.  
  49.  
  50.  
  51. hope it will help.
  52. --
  53.  
  54.  
  55. =======================================================================
  56. pascal petit
  57. work's email  : petit@litp.ibp.Fr
  58.         petit@ccr-p6.ccr.jussieu.fr
  59. home's email  : pascal.petit@f7.n320.z2.fidonet.org (slow but reliable)
  60. ======================================================================
  61.