On 6/21/07, Vahid Moghaddasi <[EMAIL PROTECTED]> wrote:
Hi all,
I wrote the following simple code to sort UNIX's password file, it
works fine but I can only display the ouput on the stdout. How can I
make it write the output to a file?
Thanks,

#!/bin/perl -w
#
use strict;
open(myFILE, '|-','awk','-F:','s[$1]++==0' ) or die $!;
open(passwdFH, "passwd");
while (<passwdFH>) { print myFILE; }
close(myFILE);

Well, first you don't use awk inside of Perl.  This is about as useful
as riding a bike on a bus.

#!/usr/bin/perl

use strict;
use warnings;

open my $out, '>', "outputfile"
       or die "could not open outputfile: $!";

open my $in, '<', 'passwd'
       or die "could not open passwd: $!";

my %h;
while (<$in>) {
       print $out $_ unless $h{(split ':')[0]}++;
}

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


Reply via email to