wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes Help needed to sort file names using bash shell script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Help needed to sort file names using bash shell script" Watch "Help needed to sort file names using bash shell script" New topic
Author

Help needed to sort file names using bash shell script

Pranav Bhasker
Greenhorn

Joined: Feb 05, 2013
Posts: 1
Hi All, I am new to Unix. I need some help in sorting file names. I have a list of files as below:

FILE10_11_9_1_C.sql
FILE11_11_9_1_P.sql
FILE12_11-9-1-P.sql
FILE13_11-9-1-P.sql
FILE14_11_9_1_P.sql
FILE15_11_9_1_P.sql
FILE16_11_9_1_P.sql
FILE17_11_9_1_U.sql
FILE17_11_9_1_U.sql
FILE5_11_9_1_A.sql
FILE7_PKG_C.sql
FILE8_PKG_CV.sql
File1_11_9_1_E.sql
File2_11_9_1_E.sql
File3_11_9_1_C.sql
FILE4_11_9_1_P.sql

I want to sort it numerically till first underscore is encountered. For ex- as below:

File1_11_9_1
File2_11_9_1
.
.
.
File8_Pkg
File10_11_9_1

I am using the following command : ls ${path}/*.sql | sed s/^.*\\/\// | sort -n -k4 > ${path}/filelist.txt;

But, its not giving the desired result.

PLEASE ADVICE

Thanks,
Pranav
vijay sarathi bharath
Greenhorn

Joined: Feb 07, 2013
Posts: 1


found here:
http://theunixshell.blogspot.in/2013/02/sorting-files-based-upon-numeric-value.html
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
And welcome to the Ranch both of you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help needed to sort file names using bash shell script
 
Similar Threads
FileIO: java.io.FileNotFoundException
Not able to read ResultSet from as400 stored procedure
on submission JSP page disappear from browser
Running a java program with full path\class name
Regarding Collection