OK... Sorry for the multiple reports.

I modified the script again to get rid of the blank elements in the array.
You should now have the array 'data' which holds the name of the members
without any trailing or leading whitespaces.


Take Care,
William


----- Original Message -----
From: "William Martell" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 22, 2003 2:00 PM
Subject: Fw: Newbie trying to cleanup/format text file


>
> ----- Original Message -----
> From: "William Martell" <[EMAIL PROTECTED]>
> To: "William Martell" <[EMAIL PROTECTED]>
> Sent: Monday, December 22, 2003 1:58 PM
> Subject: Re: Newbie trying to cleanup/format text file
>
>
> > Hi Stuart,
> >
> > I modified some of the code and it works better now.  I now have an
array
> > named 'data' that holds the names of the members.
> >
> >
> > I attached the code and the sample input.
> >
> > HTH,
> > William Martell
> > Dallas Texas
> > ----- Original Message -----
> > From: "William Martell" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Monday, December 22, 2003 12:57 PM
> > Subject: Re: Newbie trying to cleanup/format text file
> >
> >
> > > The code I posted will get rid of the unwanted text and extract the
> names
> > of
> > > the members, putting them in an array.
> > >
> > > Take a look at my code again.  It should work.
> > >
> > > #!/perl
> > >
> > > open(INFILE, "stuart_clemens_ibm.txt") || die "Could not open file";
> > >
> > >
> > > @data;  #declare array for later use
> > >
> > > # read file line by line
> > > while ( $line = <INFILE> ){
> > >
> > > # get rid of all other lines
> > > $a = "Group name";
> > > $b = "Misc";
> > > $c = "Comment";
> > > $d = "These are the FOOBAR users";
> > > $e = "Members";
> > > $f =
> > >
> >
>
"---------------------------------------------------------------------------
> > > ----";
> > > $g = "The command completed successfully.";
> > >
> > >
> > > # get rid of group name
> > > $line =~ s/$a//;
> > >
> > > # get rid of Comment
> > > $line =~ s/$b//;
> > >
> > > # get rid of Misc
> > > $line =~ s/$c//;
> > >
> > > # get rid of "These are the foobar users
> > > $line =~ s/$d//;
> > >
> > > # get rid of Members
> > > $line =~ s/$e//;
> > >
> > > # get rid of dashes
> > > $line =~ s/$f//;
> > >
> > > # get rid of command completed
> > > $line =~ s/$g//;
> > >
> > > # get rid of blank lines
> > > #$line =~ s/^\n//;
> > >
> > > # get the member names from each column
> > > $col1 = substr($line, 0,24);
> > > $col2 = substr($line, 25,24);
> > > $col3 = substr($line, 50,24);
> > >
> > > # push the names onto an array
> > > push @data, $col1;
> > > push @data, $col2;
> > > push @data, $col3;
> > >
> > >
> > >  }
> > >
> > >
> > > # print the array
> > > print @data;
> > >
> > >
> > >
> > > I did not include code that would remove the leading and trailing
spaces
> > > from each element in the array.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Monday, December 22, 2003 12:41 PM
> > > Subject: re: Newbie trying to cleanup/format text file
> > >
> > >
> > > > I kept working at it and was finally able to get rid of the unwanted
> > lines
> > > > in the text file using a series of nested if's.  It's certainly not
> > > > elegant, but it works !
> > > >
> > > > Surely there's a more efficient way to get rid of the unwanted
lines.
> > > >
> > > >  Anyway, here's what I came up with for now.  This leaves the names
in
> > > > one, two, or three columns, but I know how to reformat them into one
> > name
> > > > per column.
> > > >
> > > > #!/usr/bin/perl -w
> > > > use strict;
> > > > $_ = "";
> > > > open(INFILE, "c:\\foobar.txt")or die "sourcefile open failed - $!";
> > > >
> > > > while (<INFILE>){
> > > >      if (not $_ =~ /^The request/){
> > > >       if (not $_ =~ /^Group/){
> > > >        if (not $_ =~ /^Comment/){
> > > >         if (not $_ =~ /^Members/){
> > > >          if (not $_ =~ /^------/){
> > > >           if (not $_ =~ /^The command/){
> > > >            if ($_ =~ /\S/){
> > > >             print $_ ;
> > > >            }
> > > >           }
> > > >          }
> > > >         }
> > > >        }
> > > >       }
> > > >      }
> > > > }
> > > > close
> > > >
> > > > The result of this code is this:
> > > >
> > > > arod                     cschilling               csenior
> > > > ecostello                ffrank                   gbennett
> > > > LBird                    PMartinez
> > > >
> > > > ----- Forwarded by Stuart Clemons/Westford/IBM on 12/22/2003 01:47
PM
> > > > -----
> > > >
> > > > Stuart Clemons/Westford/IBM
> > > > 12/22/2003 11:16 AM
> > > >
> > > > To
> > > > [EMAIL PROTECTED]
> > > > cc
> > > >
> > > > Subject
> > > > Newbie trying to cleanup/format text file
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Hi all:
> > > >
> > > > I'm trying to cleanup and format this text file of user names, so
that
> I
> > > > have one column of user names.  Here's the text file:
> > > >
> > > > The request will be processed at a domain controller for domain
> FOOBAR.
> > > >
> > > > Group name        Misc
> > > > Comment        These are the FOOBAR users
> > > >
> > > > Members
> > > >
> > >
> >
>
> --------------------------------------------------------------------------
> > > -----
> > > >
> > > > arod                     cschilling               csenior
> > > > ecostello                ffrank                   gbennett
> > > > LBird                    PMartinez
> > > > The command completed successfully.
> > > >
> > > > I would like an output file to read like this:
> > > >
> > > > arod
> > > > cschilling
> > > > csenior
> > > > ecostello
> > > > ffrank
> > > > gbennett
> > > > LBird
> > > > PMartinez
> > > >
> > > > I know how to put the names into one column, if I don't have all the
> > extra
> > > > lines.  So, I've been trying to figure out how to eliminate all
lines
> > > > except for the names.
> > > >
> > > > I tried opening the file, then using a "not match" regex to
eliminate
> > all
> > > > lines except the name lines.  So far, I can't seem to eliminate more
> > than
> > > > one line of "not match".   Any help will be appreciated.  Here's my
> > feeble
> > > > newbie code.  This code will eliminate the "Group" line, but that's
> it.
> > I
> > > > tried adding other conditionals to eliminate other unwanted lines,
but
> > > > they don't work.
> > > >
> > > > open(FH, "c:\\foobar.txt") or die "sourcefile open failed - $!";
> > > > while
> > >
> >
>
> > > >             if (not $_ =~ /^Group/)
>
> > > >             print $_ ;
> > > >             }
> > > > }
> > >
> > >
> >
> >
>

Attachment: stuart_clemens_ibm.pl
Description: Perl program

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Reply via email to