Using Sort with a filename list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Sort with a filename list
# 1  
Old 12-08-2011
Using Sort with a filename list

I am using the following to script to sort and process files in order
Code:
find   $eventsFolder${cameraList[$i]}  -mtime -365 -name \*capture.jpg > /tmp/alarmvideos/${cameraname[$i]}.list
# use local time settings to order the events right.
export LC_ALL=C
sort /tmp/alarmvideos/${cameraname[$i]}.list -n -o /tmp/alarmvideos/${cameraname[$i]}-sorted.list


It produces the following output which is almost right but for example 101-capture.jpg is sorted incorrectly after 1000-capture.jpg, how can I correct this?
Code:
/var/www/html/zm/events/1/11/09/29/11/50/00/099-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/100-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1000-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1001-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1002-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1003-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1004-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1005-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1006-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1007-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1008-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1009-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/101-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1010-capture.jpg


Last edited by Franklin52; 12-09-2011 at 07:21 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 12-08-2011
Use the -t option to specify a field separator to sort and then supply a specific field as the sort key. You must also indicate that the key is numeric (the 'n'). In your case, the field you want is in the 14th position:

Code:
sort -t / -k 14n,14 file-with-names

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to sort the timestamp in the filename in shell script?

originally the shellscript #ln_file_name=`echo $ld_interface_date"_"${8}".csv"` #ln_file_name=`echo 201202011527_HL_HLTM1_B04A.csv` ln_file_name="*"`echo ${7}".csv"` get_file_list_1=$log_path"tm1_file_list.gfl1" cd ${source_path} echo "Try to find any file exist in the... (10 Replies)
Discussion started by: feilhk
10 Replies

2. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

3. Shell Programming and Scripting

Sort log files based on numeric value in the filename

Hi, I have a list of log files as follows: name_date_0001_ID0.log name_date_0001_ID2.log name_date_0001_ID1.log name_date_0002_ID2.log name_date_0004_ID0.log name_date_0005_ID0.log name_date_0021_ID0.log name_date_0025_ID0.log .......................................... (4 Replies)
Discussion started by: alex2005
4 Replies

4. Shell Programming and Scripting

Bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

5. Shell Programming and Scripting

URGENT!!! bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

6. Shell Programming and Scripting

Sort files by date in filename

Hi, I am a newbie to shell programming and I need some help in sorting a list of files in ascending order of date in the filenames. The file format is always : IGL01_AC_D_<YYYYMMDD>_N01_01 For example, in a directory MyDirectory I have the following files: IGL01_AC_D_20110712_N01_01.dat... (11 Replies)
Discussion started by: Yuggy
11 Replies

7. Shell Programming and Scripting

Is it Possible to sort a list of hexadecimal numbers using "sort" command?

Hello Everybody :) !!!. i have question in mind, is it possible to sort a list of hexadecimal numbers using "sort" command? (9 Replies)
Discussion started by: Kesavan
9 Replies

8. UNIX for Dummies Questions & Answers

sort files by numeric filename

dear all, i have .dat files named as: 34.dat 2.dat 16.dat 107.dat i would like to sort them by their filenames as: 2.dat 16.dat 34.dat 107.dat i have tried numerous combinations of sort and ls command (in vain) to obtain : 107.dat 16.dat 2.dat 34.dat (1 Reply)
Discussion started by: chen.xiao.po
1 Replies

9. UNIX for Advanced & Expert Users

help with sorting sequence in Unix C:sort -t ':' +0 -1 -n +1 -2 +2 -3 -o list list

Hi List is 000|2008-07-17|556543|RTJ|35-RTGJ|EYT 465|2008-11-10|567789|GHJ|45-DGHH|ETU 533|2008-09-06|567789|GHJ|45-DGHH|ETU How does it do it? sort -t ':' +0 -1 -n +1 -2 +2 -3 -o list list (6 Replies)
Discussion started by: gurvinder
6 Replies

10. Shell Programming and Scripting

Sort files by Date-timestamps available in filename & pick the sortedfiles one by one

Hi, I am new to Unix shell scripting. Can you please help me with this immediate requirement to code.. The requirement is as given below. In a directory say Y, I have files like this. PP_100000_28062006_122731_746.dat PP_100000_28062006_122731_745.dat PP_100000_28062006_122734_745.dat... (4 Replies)
Discussion started by: Chindhu
4 Replies
Login or Register to Ask a Question