The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-27-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
If you only use the output from find once, you don't really need to put it in a variable.

My suggestion would be to extract the sequence number and the database to separate fields, and sort numerically on the sequence number.


Code:
find logon_updates -name "*.sql" -print |
while read f
do
  g=$(echo $f | cut -b15-)
  h=$(echo $f | cut -b15-18)
  echo $h:$g
done | 
sort -t : -k1n

Once you are confident that this works correctly (I don't have the data to test on), you can continue the pipeline:


Code:
... sort -t : -k1n |
cut -d: -f2- |
while read f; do
  sql PERFORM ACTS OF horror WITH "$f" USING BIG STICK
done

If the output from find is fairly regular, probably you could find some clever options which would allow you to pass that directly to sort without the while look. Maybe pass the output from find through sed to temporarily regularize it?

Maybe something like this would work already?


Code:
find -name "*logon_structure.sql" -print |
sort -t / -k2n


Last edited by era; 04-27-2008 at 05:17 AM.. Reason: Oops, sort -t (not -d!)