linux-admin.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Perl : split +sort
@ 2002-06-02  8:32 David Jackson
  0 siblings, 0 replies; only message in thread
From: David Jackson @ 2002-06-02  8:32 UTC (permalink / raw)
  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";
}



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-06-02  8:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-02  8:32 Perl : split +sort David Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).