SPUG: Output files

William Rowden rowdenw at eskimo.com
Mon Apr 2 20:36:09 CDT 2001


Did I miss a thread?  I don't see that anyone has answered this
question.  (I notice because I wait until the end of a thread to
decide if I'll save its messages.  Few trim their replies, so the
final message usually contains most of the thread.)

On Mar 22, Jafaar Nyang'oro wrote:
> I need to create a script that would format the output from
> files created by processes running in Windows NT to look like
> the output that has been created by UNIX processes.
> 
> I have included the files in question below. I'll appreciate for
> any pointers on how to write that sort of a script. In all,
> there are three files: sysinfo.out, contacts.out, and dept.out

A straightforward--but perhaps not very clever--approach would be as
follows:

	1.  Write regular expressions for relevant information.
	2.  Capture changing information in variables.
	3.  Print new files by placing variables in standard text.

> file: sysinfo.out
> 
> 
> Run Date: Tue Mar 20 16:17:36 CST 2001
> Operating System: SunOS

A sample that prints in this format is below.  Hopefully your Perl
executable isn't in the bizarre location mine is.

-----8<-----
#!/usr/local/bin/perl5 -w

$dozfile = "nt-sysinfo.out";
$nixfile = "sysinfo.out";

open (NT, "< $dozfile\0") or
    die "Can't open Windoze file $dozfile for reading: $!\n";
open (NIX, "> $nixfile\0") or
    die "Can't open *nix file $nixfile for reading: $!\n";

while (<NT>) {
    next if /^\s*$/;    # Ignore blank lines.
    s/\s+$//;           # Remove trailing white space.
    if (/^(\w{3} \w{3} \d{1,2} \d{2}:\d{2}:\d{2}) (\d{4})$/) {
	$date = $1;
	$year = $2;
    }
    elsif (/^NT Type: (.*)$/) {
	$OS = $1;
    }
    # elsif etc.
}

print NIX <<EOF
Run Date: $date CST $year
Operating System: $OS
EOF
# Include additional lines above the EOF.
-----8<-----

> file: contact.out

This one looks the same to me.

> file: dept.out
> 
> Department(s): 704dss

What's different about this?

> file: nt-sysinfo.out
> 
> Thu Mar 22 01:27:20 2001
> NT Type: NT Advanced Server

The REs above capture these.
-- 
    -William
PGP key: http://www.eskimo.com/~rowdenw/crypt/pgp/rowdenw.asc
Fingerprint: 00C9 6887 F073 A261 CE06  EC88 7D75 13BD 1221 2BA9
I'm not left-handed either.




 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list