[Table of Contents (Book)]

Usage Examples

This chapter shows various examples of using ALL on the supported operating systems.

It might be subject to discussion whether the following examples are the best way to do what is done in each individual case. It is a fact, however, that ALL can be used in the ways shown.

Categories of Sample Tasks

Batch Related Tasks | File Related Tasks | Text Related Tasks | WWW Related Tasks



Batch Related Tasks

[Categories of Sample Tasks]



File Related Tasks

[Categories of Sample Tasks]



Text Related Tasks

[Categories of Sample Tasks]



WWW Related Tasks

[Categories of Sample Tasks]

Batch Related Tasks

Execute commands in specific intervals

There are occasions where it is necessary to avoid race conditions or you must make sure that something only happens after a specific amount of time has passed.

ALL can do this with a command like the following:

all *.* "copy !fs! s:\target" -w60

The above command copies all files in the current directory to a network directory. Because another program on another computer at the receiving end needs a lot of time to work on the files but the machine has little disk space available (files are deleted after processing) we must make sure that the target directory does not run out of disk space. This is done by waiting 1 minute after copying before the next file is sent. The -w option is used to achieve this.

[Table of Tasks] [Table of Contents]



File Related Tasks

Copy files whose name contains a specific string

Under Unix, and maybe other operating systems, this could be effected by a command like the following where the string searched might be "test" or "tast":

cp *t[e|a]st* ..

The command copies the files in question to the parent directory. Under MS-DOS, this would not be possible, because wildcard handling is very poor (yes, pattern matching is too, so I used a grep tool which does not come with DOS).

ALL can do this with a command like the following:

dir /b | grep "t[e|a]st" | all "copy !fn!!fe! .." -o -e -c

The combined -o -e options create a command file (-o) and execute it (-e) directly. The -c option lets ALL ask you for confirmation before copying.

[Table of Tasks] [Table of Contents]



Run a number of programs and delete them selectively

Execute all basic programs in the current directory one after the other and after exiting each program ask whether the program should be deleted.

ALL can do this with a command like the following for each file:

all *.bas "gwbasic !fn! & del !fs!" /C

[Table of Tasks] [Table of Contents]



Rename files according to their ordinal number in a list of files

The situation is that we have a number of MIDI sound files which we want to play on our home page, depending on the second of the minute in which the sound file is called. We do this in JavaScript but do not want to use an array but just the value of the current second.

Thus we need the second in the file name, but we have only lots of sound files with different names. This task is effected as follows:

all *.mid "ren !fn!!fe! number!ln!" -o -e

The following commands might be executed:

ren B10201.MID number1.mid
ren AIRGSTR.MID number2.mid
ren BACHVI.MID number3.mid
ren BB5M1.MID number4.mid
ren B1006A1.MID number5.mid
ren BACH-2.MID number6.mid
ren BACHA1.MID number7.mid
ren BACHA3.MID number8.mid
ren BACHJESU.MID number9.mid
ren PREL2-2.MID number10.mid
ren APLICA.MID number11.mid

Because the seconds in a minute start with 0, not with 1, the output would not be readily usable. The next ALL command results in what we want:

all *.mid "ren !fn!!fe! number!ln!" -o -e -B0

The -B option sets the numbering base from the default value of 1 to the desired value of 0. The output looks like this now:

ren B10201.MID number0.mid
ren AIRGSTR.MID number1.mid
ren BACHVI.MID number2.mid
ren BB5M1.MID number3.mid
ren B1006A1.MID number4.mid
ren BACH-2.MID number5.mid
ren BACHA1.MID number6.mid
ren BACHA3.MID number7.mid
ren BACHJESU.MID number8.mid
ren PREL2-2.MID number9.mid
ren APLICA.MID number10.mid

Now we have exactly the result which was needed.

[Table of Tasks] [Table of Contents]



Create a directory with the current date as its name

The following ALL command uses the date variables that are provided by default to create a directory with the current date as its name.

echo . | all "mkdir !yy!!mm!!dd!"

If no input data is supplied to ALL some dummy input needs to be provided which is achieved using the echo . command which just pipes an empty line to ALL.

The rest of the command is very simple: the mkdir command is given the current system year (last two digits only), month and day to act on. The whole command is then passed to the operating system for execution.

The output of the above command on my system looked like this:

ALL/32 V2.16.0 Copyright (c) 1992 - 1998  Michael Walter
mkdir 980117
ALL: Number of output records: 1

[Table of Tasks] [Table of Contents]



Concatenating files in arbitrary order

There may be occasions where a number of files may have to be concatenated in an order that is arbitrary and cannot be achieved by automatic means like sorting. In such a case you would create a list of the files in the desired order with one file specification on a line.

This file might look like this:

02.txt
01.txt
03.txt
09.txt
08.txt
05.txt
04.txt
06.txt
07.txt

The following ALL command will paste together the files named in the file list in the order required. Before it does so, it deletes file allfiles.txt if it exists by prefixing the rest of the commands with the command added to the -p option.

all files.dat "type !fn!!fe! >> allfiles.txt" "-pif exist allfiles.txt del allfiles.txt" -t

The output of the above command on my system looked like this using the -t (test) option:

ALL/32 V2.16.0 Copyright (c) 1992 - 1998  Michael Walter
if exist allfiles.txt del allfiles.txt
type 02.txt >> allfiles.txt
type 01.txt >> allfiles.txt
type 03.txt >> allfiles.txt
type 09.txt >> allfiles.txt
type 08.txt >> allfiles.txt
type 05.txt >> allfiles.txt
type 04.txt >> allfiles.txt
type 06.txt >> allfiles.txt
type 07.txt >> allfiles.txt
ALL: Number of output records: 9

In order to really execute the above ALL command line the -t option would have been replaced with the -o -e option combination.

[Table of Tasks] [Table of Contents]



Rename hundreds of files into a convention

The following problem was presented in a Usenet newsgroup:

 ...
 I have the need to rename hundreds of files into a convention, e.g.,
 
 this.txt
 that.txt
 those.txt
 
 -into-
 
 xyz01.txt
 xyz02.txt
 xyz03.txt
 
 Where is such a utility? ...

An ALL command like the following would do the job:

all *.txt "ren !fs! xyz!n[7,2]!!fe!" -o -e

The output of the above command on my system looked like this using the -t (test) option:

...
ren I:\ALL\TST\GEN\FCONCAT\01.TXT xyz01.TXT
ren I:\ALL\TST\GEN\FCONCAT\02.TXT xyz02.TXT
ren I:\ALL\TST\GEN\FCONCAT\03.TXT xyz03.TXT
ren I:\ALL\TST\GEN\FCONCAT\04.TXT xyz04.TXT
ren I:\ALL\TST\GEN\FCONCAT\05.TXT xyz05.TXT
ren I:\ALL\TST\GEN\FCONCAT\06.TXT xyz06.TXT
ren I:\ALL\TST\GEN\FCONCAT\07.TXT xyz07.TXT
ren I:\ALL\TST\GEN\FCONCAT\08.TXT xyz08.TXT
ren I:\ALL\TST\GEN\FCONCAT\09.TXT xyz09.TXT
...

[Table of Tasks] [Table of Contents]



Create a file with the current date in its name

The following problem was presented in a Usenet newsgroup:

...
I am writing a batch file in which I am creating a file which needs to
be TIME STAMPED i.e. the name of the file should have the current time
in it. Can anyone tell me how to access the system time in a batch file.
...

An ALL command like the following would do the job:

echo 1 | all "echo.> !hh!!mn!!ss!.dat"

The output of the above command on my system looked like this using the -t (test) option:

...
echo.> 071710.dat
...

The ALL command above creates a file which contains nothing but an end-of-line character (combination). Using another command like touch, for example, which is not a standard DOS command, however, a completely empty file could have been created.

[Table of Tasks] [Table of Contents]



Text Related Tasks

Indent all records in a file

The following ALL command will do this. If your operating system has a command or a tool called indent this would be preferable, though.

all infile.txt "~t!r!" /t /b /W /ooutfile.txt

This command indents all records in file infile.txt by one tab and writes them to file outfile.txt. The /t option prevents execution of the output lines as commands, the /b option forces blank lines to be kept in the output, and the /W option preserves any whitespace (blanks and tabs) at the beginning and end of the template string.

[Table of Tasks] [Table of Contents]



Add line numbers to a file

In order to prefix the records in a file with line numbers the following ALL command can be used:

all lineno.dat "!n!: !r!" -b -t -olineno.out -v0

The result of the above command will look as follows:

00000001: This is line 1
00000002:
00000003: This is line 2
00000004:
00000005: This is line 3
00000006:
00000007: This is line 4
00000008:
00000009: This is line 5
00000010:
00000011: This is line 6
00000012:
00000013: This is line 7
00000014:
00000015: This is line 8
00000016:
00000017: This is line 9
00000018:
00000019: This is line 10
00000020:


The input file is shown below. It was generated by another ALL command:

int 10 | all "This is line !ln!~n" -v0 -t -olineno.dat

This is line 1

This is line 2

This is line 3

This is line 4

This is line 5

This is line 6

This is line 7

This is line 8

This is line 9

This is line 10

The int program just prints the numbers from 1 to 10 each on a line of its own thus giving ALL 10 input records to work with. The contents, which happens to subsequent numbers in this case, does not matter..

[Table of Tasks] [Table of Contents]



WWW Related Tasks

Create an HTML file to browse through graphics

The easiest way to look at a larger number of GIF or JPEG files will probably be to load them into a WWW browser. The browser, however, requires specific HTML code to be put around the graphics.

ALL can do this with a template file and a command like the following:

dir *.gif *.jpeg /b | all -Timg2html.tpl -S# -E$ -t "-p<HTML><BODY>" "-a</BODY></HTML>"

The template file img2html.tpl would look like this:

<IMG SRC="!r!">!;r!</IMG><BR>

As the template file is very small it would not have been strictly necessary. The example illustrates the use of a template file, though.

Some people may find the syntax needed here somewhat weird. With a bit of practice it is quite easy to understand. Such code would be embedded in a batch file anyway. The actual call of such a batch file would look like

img2html *.gif *.jpeg > images.htm

First, the DIR command makes a list of the names of all GIF and JPEG files in the current directory which it passes to ALL. ALL accepts the input data and consults a template file in order to find out how to output the data. Together with the strings to place at the beginning (-a option) and at the end of the input file (-p option) the data found in the input enriched with some HTML code make up the output HTML file.

ALL uses some special characters like the split character that is set with the -S option and tells ALL which character in the input means the beginning of a new command or record. Another special character is the escape character denoted by the -E option. This character is used in special sequences like ~n (new line) and is a tilde by default. Because both characters have been found in file names, however, we set some less often used ones instead.

The resulting HTML file looks like this:

<HTML><BODY>
<IMG SRC="ArrowLeft.gif">arrowleft.gif</IMG><BR>
<IMG SRC="ArrowRight.gif">arrowright.gif</IMG><BR>
<IMG SRC="backarrow.gif">backarrow.gif</IMG><BR>
<IMG SRC="Background.gif">background.gif</IMG><BR>
<IMG SRC="banner_contact.gif">banner_contact.gif</IMG><BR>
<IMG SRC="gradient(1).gif">gradient(1).gif</IMG><BR>
<IMG SRC="H-MerkurWeihnachten.gif">h-merkurweihnachten.gif</IMG><BR>
<IMG SRC="bg_selbstdar.jpeg">bg_selbstdar.jpeg</IMG><BR>
</BODY></HTML>

[Table of Tasks] [Table of Contents]



Create an HTML table from tabular ASCII/ANSI data
(e.g. the TCP/IP hosts file)

In a TCP/IP network you may have a central hosts data file which handles the assignment of names to IP numbers.

In order to make this mapping table available in the company's intranet you may want to include the table as an HTML file. Because the mapping table may be subject to constant change the HTML table needs to be created automatically whenever the respective page is called or in regular intervals.

ALL can create an up-to-date HTML table from the hosts data file on the fly using a command like the following:

all hosts /s2 /Thosts.tpl /Phosts.pre /Ahosts.pst /t /ohosts.htm

The above call would of course be buried in a batch file with a short name and few or no parameters.

The command used here first skips the first two lines in the input file which are known to be comment text about the file. Then the output is compiled by first sending some introductory HTML code required to make up a valid HTML document. Then the actual name and IP number data are inserted followed by the closing HTML code. The complete HTML output is written to the file specified using the /o(utput) option and not executed (/t(est) option).

The prefix file hosts.pre whose contents is inserted into the output file right before the contents generated by the command template would look like this:

<html>
<head>
<title>Network Hosts And IP Addresses</title>
</head>

<body bgcolor="#FFFFFF" text="#000080"
      link="#0000FF" vlink="#800080" alink="#FFFFFF">

<font face="Arial" color="#0000A0">

<center>
<h1 align="center">Network Hosts And IP Addresses</h1>
</center>

<center>
<table border=1>
<tr>
<th width=300>Address</th><th width=300>Name</th>
</tr>

The template file hosts.tpl would look like this:

<tr>
<td>!p2!</td><td>!p1!</td>
</tr>

The append file hosts.pst whose contents is inserted into the output file right after the contents generated by the command template would look like this:

</table>
</center>
</font>
</body>
</html>

The resulting HTML file looks like this when viewed with the browser:

Network Hosts And IP Addresses

AddressName
160.9.200.1mycomp
160.9.200.2yourcomp
160.9.200.3hercomp



[Table of Tasks] [Table of Contents]





[Table of Contents (Book)]