>>>>> "John" == John W Krahn <[EMAIL PROTECTED]> writes:
John> Are you sure you want to modify /etc/passwd? Which field do you
John> want to sort on?
And if you want to modify /etc/passwd, you should be using vipw,
because vipw will lock the file for you, and verify some sanity checks
the updated data to keep you from shooting yourself in the foot.
#!/usr/bin/perl
unless (@ARGV) {
# no argument passed, so call ourselves inside vipw:
$ENV{EDITOR} = $0; # vipw will call us now instead of vi/emacs/whatever
exec "vipw";
die "Cannot exec vipw: $!";
}
# argument passed means that vipw has called us with a temp filename
# edit it inplace
$^I = "~";
# and all at once (for reasons that are hard to explain here)
$/ = undef;
my @lines = split /\n/, <>; # only one read gets the entire file
# anything we print replaces that entire file
@lines = sort @lines; # here's the active step - replace as you wish
print map "$_\n", @lines;
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]