home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / SAW / saw_1.0.readme < prev    next >
Text File  |  2000-08-17  |  3KB  |  100 lines

  1. Short:    Alternative to strip a given word from a string.
  2. Author:   agneta.nord@swipnet.se (Agneta Nord)
  3. Uploader: agneta.nord@swipnet.se (Agneta Nord)
  4. Version:  1.0 (7.12.99)
  5. Type:     util/cli
  6.  
  7. Name:
  8.  
  9.   The name derivates from "Strip A Word".
  10.  
  11. Purpose:
  12.  
  13.   I wrote this to simplify scripting while I was dealing with
  14.   logfiles. Usage is within scripts. 'saw' deals with arguments
  15.   only. I can see no relevance in interactive use.
  16.  
  17.   If You don't do scripts, You probably don't find any use in
  18.   this "utility".
  19.  
  20. Template:
  21.  
  22.   saw <word_number> <string>
  23.  
  24.   'word_number' is a number from 1 and up to 999.
  25.  
  26.   'string' is the literal string or a variable that contains
  27.   a number of words from which a particular word is searched.
  28.  
  29. Results:
  30.  
  31.   The word is output to stdout and can be redirected to a file
  32.   or used to set a variable. A trailing newline is not appended
  33.   intentionally. I didn't want that as it can be used to extract
  34.   a word that is to be joined with other files where a newline
  35.   is not desired. If You need a newline You redirect the output
  36.   to a variable and use ECHO which append a newline character
  37.   for You.
  38.  
  39.   If You point to a word beyond the list, a word_number that is
  40.   higher than the number of words, 'saw' exits with a warn and
  41.   give no output. See examples below for usage.
  42.  
  43.   If word_number is not a numeric positive integer You'll have
  44.   a WARNing and not a FAIL.
  45.  
  46. Examples:
  47.  
  48.   ---------
  49.  
  50.   The ENV:vehicles contains "car train boat bike":
  51.  
  52.     # saw 3 $vehicles >vehicle
  53.     # more vehicle
  54.     boat
  55.     #
  56.  
  57.   ---------
  58.  
  59.   The same contents in ENV:vehicles:
  60.  
  61.     # saw 3 $vehicles
  62.     boat#
  63.  
  64.   ---------
  65.  
  66.   Example, fictive logfile excerpt:
  67.  
  68.     6.12.99 1:15:32 pppd: Local IP 123.234.3.56 recieved
  69.  
  70.   If You want the IP adress for insertion in an html document,
  71.   in a script You could write something like:
  72.  
  73.     set ipstring `search <logfile> "Local IP" nonum`
  74.     saw 6 $ipstring >ip  ; from the example above -> 192.168.1.15
  75.     if warn              ; something went wrong
  76.       quit               ; so we bail out
  77.       endif
  78.     join head ip tail to myaddress.html
  79.     unset ipstring
  80.  
  81.   ---------
  82.  
  83.   'saw' could also be used to test for a number of words in a string:
  84.  
  85.     set fruit banana apple orange pineapple pear
  86.     saw 6 $fruit >nil:
  87.     if warn
  88.       echo "There is less than 6 fruits."
  89.       quit
  90.       endif
  91.     echo "There is 6 fruits or more."
  92.  
  93.   ---------
  94.  
  95. So what? I use "ECHO START=32 LEN=12 NOLINE".
  96.  
  97.   Well, in some cases the length of some words are not static
  98.   and tests which could be tedious and error prone would have
  99.   to be performed by the script.
  100.