Hi;
I have a legacy Perl script that I need to modify.
The current output is a set of zero or more space separated strings where
each substring is a string of of three dash-separated substrings.
I want to sort these space separated strings based on the middle of the
dash-separated substring.
The regex for the space-separated sub string is not exactly, but close to
the following regex.
[a-z0-9][a-z0-9]+-[A-Z][A-Z][A-Z]0z0r[1-9a-z][1-9]+-[c-z][a-z][1-9]
Here is what I tried with awk, tr and sort:
echo "example matching long string of real world data" | tr ' ' '\n' | awk
-F\- '{print $1, $2, $3}' | sort -d -k2 | tr ' ' '-' | tr '\n' ' '
This does what is intended although I'd sure like to be able to simplify
that and have not figured out how to do it.
So should I do the same thing in Perl (ie: accumulate in an array with push,
then split, then sort?, then print)?
Or is there a more direct way?
I need to keep the Perl is simple and as maintainable as possible.
Thanks in advance for your advice.
Ken Wolcott
[email protected]