The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 -->
  #1 (permalink)  
Old 04-27-2008
dlm1065 dlm1065 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 1
help newb at linux and bash need numeric script sort

I am trying to setup to automatically import a series of mysql database files. I am doing manually now and its a royal pain.

All the sql files are sequentially numbered in a format of 4 numbers underscore text with spaces replaced by underscores.

example:
Quote:
logon_updates/2334_third_file.sql
logon_updates/1234_first_file.sql
logon_updates/1345_second_file.sql
There are 3 databases each setup in the same fashion. The main directory has the database structure file higher sequence replacing lower sequence. Each database has its own subdirectory with sequenced updates the files with numbers higher than the structured files need to be loaded in numerical sequenced. There are duplicate sequence numbers in the update directories those all have to be loaded before the next number.

I figured I can do this to gain the proper structure file as they do not have duplicate numbers.

Quote:
list=$(find -name "*logon_structure.sql" -print)
for f in $list;
do
g=$(echo $f | cut -b3-6)
if [ $g -ge $lnum ]; then
lnum=$g
fi
done
I tried the below code getting rid of the directory name with cut but they are in the wrong order, they are in alphabetic not numeric order.
The variable h has the number alone and g has the full file name .
Quote:
list=$(find logon_updates -name "*.sql" -print)
for f in $list;
do
g=$(echo $f | cut -b15-255)
h=$(echo $f | cut -b15-18)
if [ $h -gt $lnum ]; then
echo $g
fi

done
I lack a lot of basic knowledge under linux that I had in a dos/windows environment.

I have been looking at this code so long I can't see the forest for the trees, if you know what I mean. So any suggestions to get me on the right train of thought would be greatly appreciated

Thanks,
dlm1065

Last edited by dlm1065; 04-27-2008 at 03:36 AM..