The UNIX and Linux Forums  

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux distro from bash script Samtim74 Shell Programming and Scripting 1 08-19-2008 03:04 AM
Perl code to differentiate numeric and non-numeric input Raynon Shell Programming and Scripting 11 08-04-2007 11:32 AM
how to numeric sort on field time rahulspatil_111 Shell Programming and Scripting 1 04-27-2007 12:52 PM
Sort (bash command) booboo Shell Programming and Scripting 5 03-31-2006 08:18 PM
Floating point numeric comparisions in bash borncrazy Shell Programming and Scripting 2 03-27-2005 08:39 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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 04:36 AM..
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0