Using PARSE.CMD
by Dallas E. Legan

Following are examples of input to the filter along with a variety
of things to try.

1) First, a few lines of test input, generated on my computer using
DIR /N:

The volume label in drive C is ACC2.
The Volume Serial Number is 25C0:E415.
Directory of C:\OS2\APPS

 5-09-97   9:04a     <DIR>           0  .
 5-09-97   9:04a     <DIR>           0  ..
 5-09-97   9:04a     <DIR>           0  DLL
10-31-94   7:45p     55076           0  EPM.EX
10-31-94   7:45p     57321           0  EXTRA.EX
10-31-94   7:45p     32480           0  EPM.EXE
10-31-94   7:45p     21328           0  EPMHELP.QHL

2) DIR /N | parse  or  DIR /N | parse ";" 
  
The volume label in drive C is ACC2.
The Volume Serial Number is 25C0:E415.
Directory of C:\OS2\APPS

 5-09-97   9:04a     <DIR>           0  .
 5-09-97   9:04a     <DIR>           0  ..
 5-09-97   9:04a     <DIR>           0  DLL
10-31-94   7:45p     55076           0  EPM.EX
10-31-94   7:45p     57321           0  EXTRA.EX
10-31-94   7:45p     32480           0  EPM.EXE
10-31-94   7:45p     21328           0  EPMHELP.QHL
  
Notes:  The program was designed so that with no script it would
simply echo the input to output.

3) DIR /N | parse ". =41 US" 
  




.
..
DLL
EPM.EX
EXTRA.EX
EPM.EXE
EPMHELP.QHL
  
Notes:  Here it is doing what this program was originally intended
for, to strip out the file names from a listing that include other
columns of data that is not wanted.  The script consists of a simple
PARSE template that splits the data in each line at column 41, with
the '=41' part of the template.  All data before column 41 is
pitched into a throw away 'black hole', '.', and that after column
41 is stored in variable 'US', the parse program's default output
variable.  The name US was chosen as an acronymn for 'UnderScore'
('$_') from Perl, where it is the default for many operations when a
variable isn't specified.

4) DIR /N | parse ". . . . US" 

  
drive C is ACC2.
is 25C0:E415.


 .
 ..
 DLL
 EPM.EX
 EXTRA.EX
 EPM.EXE
 EPMHELP.QHL
  

Notes:  This is an alternate way of doing the same thing as in case
3 above.  The template is simply to put the first four columns of
non-blank data in '.'s, and the fifth in US for output.  If there
had been trailing data after the file names, it could have been
disposed of with a template of ". . . . US .", assuming no file
names had embedded blanks (a very bad practice).

5) DIR /N | parse ";us=Word(us,5)" 
  
drive
is


.
..
DLL
EPM.EX
EXTRA.EX
EPM.EXE
EPMHELP.QHL
  
Notes:  Yet another way of performing the original task.  In this
case, the parse command template defaults to storing the input into
variable US, and the REXX standard library function Word strips out
the fifth blank delimited column (on one line a 'word') of the input
data.

6) DIR /N | parse ";us=SubWord(us,5,1)" 
  
drive
is


.
..
DLL
EPM.EX
EXTRA.EX
EPM.EXE
EPMHELP.QHL
  
Notes:  And yet another way, using a slightly more versatle function
Subword, which could have included more than one blank delimited
column if it had been desired (and more available).

7) DIR /N | parse "; US='>' US;" 
  
>
> The volume label in drive C is ACC2.
> The Volume Serial Number is 25C0:E415.
> Directory of C:\OS2\APPS
>
>  5-09-97   9:04a     <DIR>           0  .
>  5-09-97   9:04a     <DIR>           0  ..
>  5-09-97   9:04a     <DIR>           0  DLL
> 10-31-94   7:45p     55076           0  EPM.EX
> 10-31-94   7:45p     57321           0  EXTRA.EX
> 10-31-94   7:45p     32480           0  EPM.EXE
> 10-31-94   7:45p     21328           0  EPMHELP.QHL
  
Notes:  Here, leading '>' characters were prefixed to each line, as
might be done when quoting email for a reply.  No template was
provided, so each line of input was put into variable US by default
(nothing preceeds the first ';' in the script.).  Then character
string '>' was concatenated with the blank concatenation operator '
' to the value of string US and stored over the original value in
US.

8) DIR /N | parse ";US=NR US;" 
  

1
2 The volume label in drive C is ACC2.
3 The Volume Serial Number is 25C0:E415.
4 Directory of C:\OS2\APPS
5
6  5-09-97   9:04a     <DIR>           0  .
7  5-09-97   9:04a     <DIR>           0  ..
8  5-09-97   9:04a     <DIR>           0  DLL
9 10-31-94   7:45p     55076           0  EPM.EX
10 10-31-94   7:45p     57321           0  EXTRA.EX
11 10-31-94   7:45p     32480           0  EPM.EXE
12 10-31-94   7:45p     21328           0  EPMHELP.QHL
  
Notes:  Here, the line number (NR) was simply put in front of each
line of output.

9) DIR /N | parse ";US=Right(NR,3) US;" 
  

  1
  2 The volume label in drive C is ACC2.
  3 The Volume Serial Number is 25C0:E415.
  4 Directory of C:\OS2\APPS
  5
  6  5-09-97   9:04a     <DIR>           0  .
  7  5-09-97   9:04a     <DIR>           0  ..
  8  5-09-97   9:04a     <DIR>           0  DLL
  9 10-31-94   7:45p     55076           0  EPM.EX
 10 10-31-94   7:45p     57321           0  EXTRA.EX
 11 10-31-94   7:45p     32480           0  EPM.EXE
 12 10-31-94   7:45p     21328           0  EPMHELP.QHL
  
Notes:  Here, the line number was padded out to 3 characters with
the default character of space, with the Right string function, so
things line up nicer.

10) DIR /N | parse ";us=Left(us,75) Right(NR,3);" 
  
                                                                              1
The volume label in drive C is ACC2.                                          2
The Volume Serial Number is 25C0:E415.                                        3
Directory of C:\OS2\APPS                                                      4
                                                                              5
 5-09-97   9:04a     <DIR>           0  .                                     6
 5-09-97   9:04a     <DIR>           0  ..                                    7
 5-09-97   9:04a     <DIR>           0  DLL                                   8
10-31-94   7:45p     55076           0  EPM.EX                                9
10-31-94   7:45p     57321           0  EXTRA.EX                             10
10-31-94   7:45p     32480           0  EPM.EXE                              11
10-31-94   7:45p     21328           0  EPMHELP.QHL                          12
  
Notes:  This time, trim or pad each line to 75 characters from the
left with the Left function, and pad the record numbers to three
characters from the right, concatenate them with the space
concatenation operator, so that the line numbering is on the right
end of each line.

11) DIR /N | parse ";IF NR < 8 THEN;ITERATE;" 
  

 5-09-97   9:04a     <DIR>           0  DLL
10-31-94   7:45p     55076           0  EPM.EX
10-31-94   7:45p     57321           0  EXTRA.EX
10-31-94   7:45p     32480           0  EPM.EXE
10-31-94   7:45p     21328           0  EPMHELP.QHL
  
Notes:  Skip the first 8 lines before printing them out.

12) DIR /N | parse ". . a b .; us=a b" 
  
label in
Serial Number
C:\OS2\APPS

<DIR> 0
<DIR> 0
<DIR> 0
55076 0
57321 0
32480 0
21328 0
  
Notes:  Parse out only the two columns for data and extended
attributes size in listing and assign them to variable 'us' for
output.

13) DIR /N | parse ". . a .;IF datatype(a,'N') THEN;t.1=t.1+a;END;DO;us=t.1;" 
  
34932530
  
Notes:  Parse out each file size, from the appropriate column.
Check it to see if it is a number.  If it is, add it to the total
stem variable.  End the loop before outputting anything on each loop
iteration.  On a final one pass grouping loop, assign the tally
value to the default output variable.  Then the tally is automaticly
printed out.

14) DIR /N | parse " a =26 b;us=reverse(a)||reverse(b);" 
  

evird ni lebal emulov ehT.2CCA si C
 rebmuN laireS emuloV ehT.514E:0C52 si
SPPA\2SO\:C fo yrotceriD

RID<     a40:9   79-90-5 .  0           >
RID<     a40:9   79-90-5 ..  0           >
RID<     a40:9   79-90-5 LLD  0           >
7055     p54:7   49-13-01XE.MPE  0           6
2375     p54:7   49-13-01XE.ARTXE  0           1
8423     p54:7   49-13-01EXE.MPE  0           0
2312     p54:7   49-13-01LHQ.PLEHMPE  0           8
  
Notes:  Split each line in two at column 26.  Glue the two halves
back together after reversing them, with no intervening space, with
the '||' operater.  (a touch of arbitrary surrealism!)

15) DIR /N | parse "a . . . b; us =a b;" 

  
The drive C is ACC2.
The is 25C0:E415.
Directory

5-09-97  .
5-09-97  ..
5-09-97  DLL
10-31-94  EPM.EX
10-31-94  EXTRA.EX
10-31-94  EPM.EXE
10-31-94  EPMHELP.QHL
  
Notes:  Strip apart the first and fifth columns of the listing and
glue them directly together for output.

16) DIR /N | parse "; IF NR > 3 THEN; ITERATE;" 
  
The volume label in drive C is ACC2.
The Volume Serial Number is 25C0:E415.
  
Notes:  Here, 'ITERATE' the boilerplate DO loop on all lines after
the third, before they are printed out, clipping them from the
printout.

17) DIR /N | parse "; US = US || RS || RS;" 
  


The volume label in drive C is ACC2.


The Volume Serial Number is 25C0:E415.


Directory of C:\OS2\APPS





 5-09-97   9:04a     <DIR>           0  .


 5-09-97   9:04a     <DIR>           0  ..


 5-09-97   9:04a     <DIR>           0  DLL


10-31-94   7:45p     55076           0  EPM.EX


10-31-94   7:45p     57321           0  EXTRA.EX


10-31-94   7:45p     32480           0  EPM.EXE


10-31-94   7:45p     21328           0  EPMHELP.QHL


  

Notes:  Two additional record seperaters ( 'RS' ) are concatenated
onto each line before it printed out, causing the output to be
triple spaced.

18) DIR /N | parse ". . . t.1 us;IF t.1 < 400 THEN;ITERATE;" 
  
drive C is ACC2.
is 25C0:E415.
 PICVIEW.EXE
 KAPP.CMD
 PU.CMD
 PARSETST.CMD
 LOADLIB.CMD
 ATLST0.CMD
 ATLST.CMD
 ATLST1.CMD
 ATLST2.CMD
 CALENDAR.CMD
 HEX.CMD
  
Notes:  Here, parse the value of the bytes in the extended attribute
part of the directory listing into stem variable t.1, and iterate if
it is less than 400 bytes.  This leaves, basically, a listing of
files with more than 400 bytes of extended attributes.

19) DIR /N | parse ". . . t.1 us;IF t.1 < 400 THEN;ITERATE;'copy 'us' a:*.*';" 
  
Wed 10-03-2001 |  4:54:22.68 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy drive C is ACC2. a:*.*
SYS1003: The syntax of the command is incorrect.
drive C is ACC2.

Wed 10-03-2001 |  4:54:22.89 | The Operating System/2 Version is 3.00
(1)[C:\OS2\APPS]copy is 25C0:E415. a:*.*
SYS1003: The syntax of the command is incorrect.
is 25C0:E415.

Wed 10-03-2001 |  4:54:23.34 | The Operating System/2 Version is 3.00
(1)[C:\OS2\APPS]copy  PICVIEW.EXE a:*.*
        1 file(s) copied.
 PICVIEW.EXE

Wed 10-03-2001 |  4:54:33.85 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  KAPP.CMD a:*.*
        1 file(s) copied.
 KAPP.CMD

Wed 10-03-2001 |  4:54:37.53 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  PU.CMD a:*.*
        1 file(s) copied.
 PU.CMD

Wed 10-03-2001 |  4:54:41.53 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  PARSETST.CMD a:*.*
        1 file(s) copied.
 PARSETST.CMD

Wed 10-03-2001 |  4:54:46.69 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  LOADLIB.CMD a:*.*
        1 file(s) copied.
 LOADLIB.CMD

Wed 10-03-2001 |  4:54:50.90 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  ATLST0.CMD a:*.*
        1 file(s) copied.
 ATLST0.CMD

Wed 10-03-2001 |  4:54:55.05 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  ATLST.CMD a:*.*
        1 file(s) copied.
 ATLST.CMD

Wed 10-03-2001 |  4:54:59.85 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  ATLST1.CMD a:*.*
        1 file(s) copied.
 ATLST1.CMD

Wed 10-03-2001 |  4:55:05.01 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  ATLST2.CMD a:*.*
        1 file(s) copied.
 ATLST2.CMD

Wed 10-03-2001 |  4:55:10.43 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  CALENDAR.CMD a:*.*
        1 file(s) copied.
 CALENDAR.CMD

Wed 10-03-2001 |  4:55:15.18 | The Operating System/2 Version is 3.00
(0)[C:\OS2\APPS]copy  HEX.CMD a:*.*
        1 file(s) copied.
 HEX.CMD
  
Notes:  This time, copy the files with greater than 400 bytes
extended attributes to the a:  floppy disk.  The string 'copy 'us'
a:*.*' , with variable US concatenated by abuttal with two literal
strings, since it doesn't make up part of any recognizable REXX
command or expression, is passed to the invoking environment for
interpretation.


Copyright 2001 Dallas E. Legan.

