From mboxrd@z Thu Jan 1 00:00:00 1970 From: "David Jackson" Subject: Perl : split +sort Date: Sun, 2 Jun 2002 02:32:57 -0600 Sender: linux-admin-owner@vger.kernel.org Message-ID: <200206020232.AA812253490@wcox.com> Reply-To: Mime-Version: 1.0 Return-path: List-Id: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Linux-Admin Howdy -- What I need to do the the contact list is split the city/state fields and than sort by state. The record format is below. And it would be nice to print the state name before each state group. Thanks in advance 1st Concept Internet, Inc. 1000 West McNab Road Suite #109 Pompano Beach, Florida 33069 --- Quickie perl script using a2p looks like this --- #!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line above if indigestible) eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift; # process any FOO=bar switches $FS = ' '; # set field separator $, = ' '; # set output field separator $\ = "\n"; # set output record separator $/ = "\n\n"; $FS = "\n"; $, = "\n"; while (<>) { chomp; # strip record separator ($Fld1,$Fld2,$Fld3,$CityState,$Fld5) = split($FS, $_, 9999); print $Fld1, $Fld2, $Fld3, $CityState, $Fld5 . "\n"; }