Re: DCL script for a dummy like me ...

From: Michael Austin (nospam_at_firstdbasource.com)
Date: 01/30/05


Date: Sun, 30 Jan 2005 01:44:25 GMT

Hein wrote:
>>I need to count the number of lines for each file at a given directory
>>and keep the result (name of the file and number of lines) in a new output
>
> file.
>
> Here are two 'one liners' to solve this:
> First one... just search with a properly wildcarded filespec and redirected
> output:
>
> $define/user sys$output linecount.tmp
> $search/noout/log *200501* ""/matc=nor
> %SEARCH-I-NOMATCHES, no strings matched
> $
> $type linecount.tmp
> %SEARCH-S-NOMATCH, U$1:[HEIN.TMP]TMP_200501_AAP.TMP;1 - 1 record
> %SEARCH-S-NOMATCH, U$1:[HEIN.TMP]TMP_200501_MIES.TMP;1 - 3 records
> %SEARCH-S-NOMATCH, U$1:[HEIN.TMP]TMP_200501_NOOT.TMP;1 - 2 records
>
> Second using perl, giving you infinite control over the output formatting:
>
> $ perl -e "$a=shift @ARGV; foreach $f (glob $a){$i=0;open (X,""<$f""); $i++
> while (<X>); print ""$i,$f\n""}" *200501*
> 1,tmp_200501_aap.tmp
> 3,tmp_200501_mies.tmp
> 2,tmp_200501_noot.tmp
>
> As a full perl program (untested) I woudl write it more like:
>
> $wildcard=shift @ARGV or die "Please provide a wildcarded filespec
> argument";
> foreach $file (glob $wildcard) {
> $lines = 0;
> open (X,"<$file") or die "Failed to open file '$file' for input";
> $lines++ while (<X>);
> print "$lines $file\n";
> }
>
> hth,
> Hein.
>
>

or you can use the lexical F$FILE_ATTRIBUTES:

$ write sys$output f$file("login.com","file_length_hint")
(85,3172) !<<<<------ first number is number of records, second is the byte count
$ sear/out=nl:/stat login.com fads !! search for nothing.

Files searched: 1 Buffered I/O count: 5
Records searched: 85 Direct I/O count: 2
Characters searched: 3172 Page faults: 28
Records matched: 0 Elapsed CPU time: 0 00:00:00.02
Lines printed: 0 Elapsed time: 0 00:00:00.06