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

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