pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Deleting rows in a file based on condition
2+ messages / 1 participants
[nested] [flat]

* Deleting rows in a file based on condition
@ 2006-02-10 17:52 Ken Hill <ken@scottshill.com>
  2006-02-10 18:00 ` Re: Deleting rows in a file based on condition Ken Hill <ken@scottshill.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Ken Hill @ 2006-02-10 17:52 UTC (permalink / raw)
  To: pgsql-sql

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.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Deleting rows in a file based on condition
  2006-02-10 17:52 Deleting rows in a file based on condition Ken Hill <ken@scottshill.com>
@ 2006-02-10 18:00 ` Ken Hill <ken@scottshill.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Ken Hill @ 2006-02-10 18:00 UTC (permalink / raw)
  To: pgsql-sql

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.
> 

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-02-10 18:00 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-02-10 17:52 Deleting rows in a file based on condition Ken Hill <ken@scottshill.com>
2006-02-10 18:00 ` Ken Hill <ken@scottshill.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox