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 A9B4B9DC829 for ; Fri, 10 Feb 2006 13:52:26 -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 31047-01 for ; Fri, 10 Feb 2006 13:52:25 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from rwcrmhc14.comcast.net (rwcrmhc14.comcast.net [216.148.227.154]) by postgresql.org (Postfix) with ESMTP id 4ADDA9DC818 for ; Fri, 10 Feb 2006 13:52:24 -0400 (AST) Received: from [10.0.1.5] (c-24-20-199-254.hsd1.or.comcast.net[24.20.199.254]) by comcast.net (rwcrmhc14) with SMTP id <20060210175220m1400dg5f4e>; Fri, 10 Feb 2006 17:52:24 +0000 Subject: Deleting rows in a file based on condition From: Ken Hill Reply-To: ken@scottshill.com To: Perl Help Content-Type: multipart/alternative; boundary="=-4EHRR8IhGyvHf6avwLu5" Organization: Scotts Hill Associates, Inc. Date: Fri, 10 Feb 2006 09:52:47 -0800 Message-Id: <1139593968.30696.10.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.071 required=5 tests=[AWL=0.070, HTML_MESSAGE=0.001] X-Spam-Score: 0.071 X-Spam-Level: X-Archive-Number: 200602/116 X-Sequence-Number: 24126 --=-4EHRR8IhGyvHf6avwLu5 Content-Type: text/plain Content-Transfer-Encoding: 7bit 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. --=-4EHRR8IhGyvHf6avwLu5 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit 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.

--=-4EHRR8IhGyvHf6avwLu5--