X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0133D9DC85A for ; Fri, 10 Feb 2006 13:59:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30048-04 for ; Fri, 10 Feb 2006 13:59:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from rwcrmhc11.comcast.net (rwcrmhc11.comcast.net [216.148.227.151]) by postgresql.org (Postfix) with ESMTP id D00E79DC829 for ; Fri, 10 Feb 2006 13:59:36 -0400 (AST) Received: from [10.0.1.5] (c-24-20-199-254.hsd1.or.comcast.net[24.20.199.254]) by comcast.net (rwcrmhc11) with SMTP id <20060210175936m1100c2ntte>; Fri, 10 Feb 2006 17:59:36 +0000 Subject: Re: Deleting rows in a file based on condition From: Ken Hill Reply-To: ken@scottshill.com To: Perl Help In-Reply-To: <1139593968.30696.10.camel@localhost.localdomain> References: <1139593968.30696.10.camel@localhost.localdomain> Content-Type: multipart/alternative; boundary="=-xgMUlyoutGFd4AnDZdhH" Organization: Scotts Hill Associates, Inc. Date: Fri, 10 Feb 2006 10:00:02 -0800 Message-Id: <1139594402.30696.16.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.074 required=5 tests=[AWL=0.073, HTML_MESSAGE=0.001] X-Spam-Score: 0.074 X-Spam-Level: X-Archive-Number: 200602/117 X-Sequence-Number: 24127 --=-xgMUlyoutGFd4AnDZdhH Content-Type: text/plain Content-Transfer-Encoding: 7bit Oops. I posted this to the wrong support list. Sorry. -Ken On Fri, 2006-02-10 at 09:52 -0800, Ken Hill wrote: > I have the following perl script that reads a fixed-width file and > replaces values in various sections of the file. > > ------------------------------------------- > open (IN, '< in.txt'); > open (OUT, '> out_test.txt'); > > while () { > > chomp; > > $first_section = substr $_, 0, 381; # extract the first > section of the record > $facilityno = substr $_, 381, 10; # extract the > facilityno field > $second_section = substr $_, 391, 1056; # extract the > second section of the record > $requestor_section=" " x 500; > # $requestor_section = substr $_, 1446, 499; # extract requestor > section of record > $third_section = substr $_, 1946, 4748; # extract third > section of record > > # print out the file with changed facilityno value ... > > print OUT "$first_section$\0039007300$\$second_section$\ > $requestor_section$\$third_section\n"; > > } > > close (IN); > close (OUT); > ------------------------------------------------ > > I want to place an "if...then" condition on the $facilityno value; > such that if the $facilityno value = 0000000000, delete the record > (e.g., don't print out that row); rather skip that row and continue > printing out the remaining rows. > > Any advice is very much appreciated. > --=-xgMUlyoutGFd4AnDZdhH Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit Oops. I posted this to the wrong support list. Sorry.

-Ken

On Fri, 2006-02-10 at 09:52 -0800, Ken Hill wrote:
I have the following perl script that reads a fixed-width file and replaces values in various sections of the file.

-------------------------------------------
open (IN, '< in.txt');
open (OUT, '> out_test.txt');

while (<IN>) {

          chomp;

          $first_section = substr $_, 0, 381;     # extract the first section of the record
          $facilityno = substr $_, 381, 10;    # extract the facilityno field
          $second_section = substr $_, 391, 1056;        # extract the second section of the record
          $requestor_section=" " x 500;
  # $requestor_section = substr $_, 1446, 499; # extract requestor section of record
          $third_section = substr $_, 1946, 4748; # extract third section of record
         
          # print out the file with changed facilityno value ...

          print OUT "$first_section$\0039007300$\$second_section$\$requestor_section$\$third_section\n";
         
}

close (IN);
close (OUT);
------------------------------------------------

I want to place an "if...then" condition on the $facilityno value; such that if the $facilityno value = 0000000000, delete the record (e.g., don't print out that row); rather skip that row and continue printing out the remaining rows.

Any advice is very much appreciated.

--=-xgMUlyoutGFd4AnDZdhH--