Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] How to remove a line in data file

Expand Messages
  • joach@direct.ca
    OK...... I would think that looking just a snip of the script might not be enough..... here is the script as it is right now...... it reads..... recopies just
    Message 1 of 8 , Jul 23, 2000
      OK...... I would think that looking just a snip of the script might not be
      enough.....
      here is the script as it is right now...... it reads..... recopies just the same
      as it was..... to bad.

      I do think that this aproach is the correct way to go read the files and recopy
      all lines except the ones starting with 19 the 19 of course represents the
      dates 1900 through to 1999

      Thankyou for the input..... but it's not debuged yet..... there is an error in
      line 30

      John


      #!/usr/bin/perl -w
      # for bat file switch - Name change!
      $infile = shift;
      $outfile = shift;

      $Cleaner="";
      open(IN, $infile) || die("Can't open input file $infile - $!");
      open(OUT, ">$outfile") || die("Can't open output file $outfile - $!");

      $header = 1;
      $count = 0;
      until ($count == $header )
      {

      $text=<IN>;
      print OUT "$text";
      $count++;

      }

      $count = 0;
      while (<IN>)
      {
      if $_ starts with 19 #line 30
      }
      else
      {
      print OUT $_;
      }
      $count++;

      Greg Webster wrote:

      > Sorry for the pseudo code, I'm in a hurry...
      >
      > while (<IN>)
      > {
      > if $_ starts with 19
      > {
      > }
      > else
      > {
      > print OUT $_;
      > }
      >
      > Don't bother deleting lines...just don't print them. If you want to deal
      > further with the lines that do not start with 19, instead bring them all into
      > an array and use a similar structure in a foreach statement that assigns the
      > goos lines to another array.
      >
      > Greg
      >
      > On Sun, 23 Jul 2000, you wrote:
      > > I am trying to piece together a small script which will scrub lines from
      > > a data file.
      > > The idea would be to delete all lines beginning with 19 and leave all
      > > other lines intact.
      > > I have tried many conbinaion and even gone back to books......... no
      > > luck......... anyone willing to have a look at this.......??
      > >
      > > TIA
      > > John
      > >
      > >
      > >
      > > while (<IN>)
      > > if ($_ =~ m/19/)
      > > {
      > >
      > > #delete the lines starting with 19 only.......the line below is
      > > not correct
      > > Chomp $_ }
      > >
      > >
      > > $_ = $Cleaner.$_;
      > > print OUT $_;
      > > $count++;
      > >
      > >
      > > ------------------------------------------------------------------------
      > > In Europe, more than 219 million people will access Internet services
      > > using mobile phones by 2003, according to Forrester Research.
      > > Learn Wireless Development on
      > > http://click.egroups.com/1/6222/2/_/12898/_/964372887/
      > > ------------------------------------------------------------------------
      > --
      > < >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
      > | | | GREG WEBSTER - greg@... | | | |
      > <_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>
      >
      > ------------------------------------------------------------------------
      > Find long lost high school friends:
      > http://click.egroups.com/1/7080/2/_/12898/_/964377640/
      > ------------------------------------------------------------------------

      close IN;
      close OUT ;




      Greg Webster wrote:

      > Sorry for the pseudo code, I'm in a hurry...
      >
      > while (<IN>)
      > {
      > if $_ starts with 19
      > {
      > }
      > else
      > {
      > print OUT $_;
      > }
      >
    • Danny Platt
      ... #!/usr/bin/perl $infile=shift; $outfile=shift; open (IN, $infile ); open (OUT, $outfile ); @temp= ; foreach $i (@temp) { print OUT $i unless
      Message 2 of 8 , Jul 23, 2000
        joach@... writes:

        > OK...... I would think that looking just a snip of the script might not be
        > enough.....
        > here is the script as it is right now...... it reads..... recopies just the same
        > as it was..... to bad.
        >
        > I do think that this aproach is the correct way to go read the files and recopy
        > all lines except the ones starting with 19 the 19 of course represents the
        > dates 1900 through to 1999

        OK, this is untested, but should work:
        ------------ Start Code

        #!/usr/bin/perl

        $infile=shift;
        $outfile=shift;

        open (IN, "$infile");
        open (OUT, ">$outfile");

        @temp=<IN>;

        foreach $i (@temp) {
        print OUT $i unless ($i=~/^19/);
        }

        close (IN);
        close (OUT);
        exit;
        ------------ End Code

        HTH

        --
        Later, Dan

        Stolichnaya!
      • joach@direct.ca
        Yes Dan.......... it work very well thank you. I learned something..... in the 4-5 hrs I spent on it. I guess you learn something new every time you try.
        Message 3 of 8 , Jul 23, 2000
          Yes Dan.......... it work very well thank you. I learned something..... in the 4-5
          hrs I spent on it. I guess you learn something new every time you try.

          John

          Danny Platt wrote:

          > joach@... writes:
          >
          > > OK...... I would think that looking just a snip of the script might not be
          > > enough.....
          > > here is the script as it is right now...... it reads..... recopies just the same
          > > as it was..... to bad.
          > >
          > > I do think that this aproach is the correct way to go read the files and recopy
          > > all lines except the ones starting with 19 the 19 of course represents the
          > > dates 1900 through to 1999
          >
          > OK, this is untested, but should work:
          > ------------ Start Code
          >
          > #!/usr/bin/perl
          >
          > $infile=shift;
          > $outfile=shift;
          >
          > open (IN, "$infile");
          > open (OUT, ">$outfile");
          >
          > @temp=<IN>;
          >
          > foreach $i (@temp) {
          > print OUT $i unless ($i=~/^19/);
          > }
          >
          > close (IN);
          > close (OUT);
          > exit;
          > ------------ End Code
          >
          > HTH
          >
          > --
          > Later, Dan
          >
          > Stolichnaya!
          >
          > ------------------------------------------------------------------------
          > Still looking for the complete Application Server solution?
          > Find answers and a $75 gift certificate at the Intraware App Server
          > Webinar. Sign up at:
          > http://click.egroups.com/1/6756/2/_/12898/_/964383688/
          > ------------------------------------------------------------------------
        • Danny Platt
          ... Never stop learning ;) -- Later, Dan Stolichnaya!
          Message 4 of 8 , Jul 23, 2000
            joach@... writes:

            > Yes Dan.......... it work very well thank you. I learned something..... in the 4-5
            > hrs I spent on it. I guess you learn something new every time you try.

            :)
            Never stop learning ;)

            --
            Later, Dan

            Stolichnaya!
          • Manolo Marzan
            Hi All, I m a newbie with DBD / DBI and I ve not used it since. Is DBD / DBI only for Unix box? Can I just download the DBI-1.13.tar.gz for Win32? If not,
            Message 5 of 8 , Jul 24, 2000
              Hi All,

              I'm a newbie with DBD / DBI and I've not used it since. Is DBD / DBI only for
              Unix box? Can I just download the DBI-1.13.tar.gz for Win32? If not, where
              and how am I going to install it on Win32?

              Cheers,


              MANOLO P. MARZAN
              Weserv Systems International
              Makati, Philippines
            • Smith, Sheldon
              If *all* you want to do is remove lines beginning with 19, other possibilities are perl -ne print if !/^19/ infile outfile or perl -pe s/^19.* Z n//
              Message 6 of 8 , Aug 4, 2000
                If *all* you want to do is remove lines beginning with 19, other
                possibilities are
                perl -ne 'print if !/^19/' infile >outfile
                or
                perl -pe 's/^19.*\Z\n//' infile >outfile

                Then use your OS to make outfile take the place of infile.

                Enjoy....

                > -----Original Message-----
                > From: joach@... [mailto:joach@...]
                >
                > I am trying to piece together a small script which will scrub
                > lines from
                > a data file.
                > The idea would be to delete all lines beginning with 19 and leave all
                > other lines intact.
              Your message has been successfully submitted and would be delivered to recipients shortly.