splitting-a-file

Pipelines v2.1

 

.....|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....10...

Home

     **** Top of file ****
   1
   2 /* The following pipeline reads the FetchMail logfile: monkey.log and extracts each
   3    group/set of monitor records; based on an ACT label: BC#, CP# and the 'Average' entries.
   4    For each log section found; the pipeline creates/appends that set of records to a file 
   5    with the name of that section.
   6
   7    The pipeline is intended to demonstrate how you can isolate sections of a file,
   8    and split off and create/append those sections to a specific output file. */
   9
  10 Address Rxpipe
  11
  12 'pipe (stagesep | endchar ? escape % reg 3)',
  13      '< &installdrive:\&installpath\examples\input\monkey.log',
  14      '| specs 1-* 1 xff n',                  /* Append an x'ff' to each record. */
  15      '| a: locate',                          /* Select records that comprise a BC# or CP#. */
  16           'anycase ws x20ff w-1 reg /BC[0-9]%|CP([0-9])/',
  17         ,
  18         /* Surround the output filename with quotes ("). */,
  19      '| specs /"&sysdrive:\Documents and Settings\&username\My Documents\/ ',
  20              '1 ws xff20 w-1 n \.log"\ n 1-* nw',  
  21      '| specs /@/ 1 1-* n',                  /* Pre-pend an (@) character. */
  22      '| split after str /@/',                /* Split records after the (@) character. */
  23      '| b: faninany',                        /* Join the streams. */
  24      '| join until str /@/',                 /* Collect records until we read a record.. */
  25         ,                                    /* ..which starts with an (@) character. */
  26      '| locate',                             /* Discard blank lines. */
  27      '| locate 1 /"/',                       /* Select records that begin with a quote ("). */
  28      '| split before str /</',               /* Split records that begin with a (<). */
  29      '| nlocate 1 /</',                      /* ..and discard them. */
  30      '| change xff x0a',                     /* Change x'ff's to newline characters. */
  31      '| cons',                               /* Display on the console. */
  32      '| >>',                                 /* Append this record section to the specified.. */
  33         ,                                    /* ..output file. */
  34      '?',
  35      'a:',
  36      '| j: locate anycase w1 /average/',     /* Select records that begin with: 'average'. */
  37      '| specs /"&sysdrive:\Documents and Settings\&username\My Documents\/', /* Surround.. */
  38              '1 w1 n \.txt"\ n 1-* nw',      /* ..the output filename with quotes. */
  39      '| specs /@/ 1 1-* n',                  /* Pre-pend an (@) character. */
  40      '| split after str /@/',                /* Split records after the (@) character. */
  41      '| k: faninany',                        /* Join the streams. */
  42      '| b:',                                 /* Send the records back to first pipeline. */
  43      '?',
  44      'j:',
  45      '| take *',                             /* Handle unselected records from second pipeline. */
  46      '| k:'
  47
  48 Say 'Hit Enter to close..'
  49 Parse Pull
  50
  51 Exit 0
     **** End of file ****