Home > Archive > PERL Beginners > June 2007 > writing to file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi all,
I have the following code to sort UNIX's password file, it works fine
but can only display on 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);
| |
| Yogesh Sawant 2007-06-23, 7:58 am |
|
Vahid wrote:
> Hi all,
> I have the following code to sort UNIX's password file, it works fine
> but can only display on 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);
here's one way (untested):
open (NEW_FILE, "> /foo/bar") or die "Failed to write to /foo/bar :
$! \n";
open (passwdFH, "passwd");
while (<passwdFH> ) {
print NEW_FILE $_;
}
close (passwdFH);
close (NEW_FILE);
cheers
Yogesh
|
|
|
|
|