|
2008-10-11 Forcing sort ordering in Unix shell scriptsThere are a number of situations in Unix shell scripts where you know
the order that the lines in your output should be in, but you can't
produce it in that order and nothing in your normal output is useful
to sort on. One common case is awk scripts that accumulate information
into arrays and then dump it out in their In this situation, some people go to bat against A variant of this trick can be used to re-order output lines that are easiest to produce together. A snippet from one of my shell script is perhaps the best illustration:
What this script wants to do is unshare a bunch of filesystems, wait
some time, and then reshare them all. However, it gets all of the
necessary information about each filesystem once, in a big chunk, so it
is most natural to generate both the unshare and the reshare command at
the same time. To insert a (Disclaimer: this is clearly at least related to Perl's Schwartzian transforms, although I think that they're not quite the same thing, and I probably picked up this shell idiom from somewhere.) (One comment.)
unix/ForcingSortOrder written at 02:03:39; Add Comment
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |