Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Sort Files based on the number(s) on the file name Post 302795737 by dsedi on Thursday 18th of April 2013 09:19:37 AM
Old 04-18-2013
Quote:
Originally Posted by franzpizzo
It is not nice but it works

Code:
printf "mysample%d\n" $( ls -1 mysample*|sed 's/mysample//'| sort -n )

Thank you for the reply.. this is working

---------- Post updated at 09:17 AM ---------- Previous update was at 09:08 AM ----------

Quote:
Originally Posted by radoulov
Code:
printf '%s\n' mysample* | sort -k1.9n

Some ls implementations (the one from the GNU coreutils, for example) support the -v option (for natural sort of (version) numbers within text):

Code:
ls -v1 mysample*

For non-interactive use, drop the -1 option.
Thanks radoulov..
Code:
ls -v1 mysample*

didn't work for us.it said
Code:
ls: Not a recognized flag: v
Usage: ls [-1ACFHLNRSabcdefgiklmnopqrstuxEUX] [File...]

but as exepcted
Code:
printf '%s\n' mysample* | sort -k1.9n

working fine. Thanks for the help.

---------- Post updated at 09:19 AM ---------- Previous update was at 09:17 AM ----------

Quote:
Originally Posted by palanisvr
Code:
for i in `cat file`
do
fld1=`echo $i | tr -d '[0-9]'`
fld2=`echo $i | tr -d '[a-z]' |tr -d '[A-Z]'`
echo $fld1 " " $fld2 >> tmp.txt
sort  -n -k2 tmp.txt |awk -F ' ' '{print $1$2}'
rm -f tmp.txt
done

Thanks Palani.we Will try this.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Sort files based on predefined values.?

How to Sort files based on predefined values.? Normally Sorting happens for the alphabetic or numberic orders.. Is there any way to sort a fields based on the Field values..? Field10 has : one two three five four six ten seven eight nine. in predefined order { one, two, three,... (2 Replies)
Discussion started by: p_prathaban
2 Replies

2. Shell Programming and Scripting

Split single file into multiple files based on the number in the column

Dear All, I would like to split a file of the following format into multiple files based on the number in the 6th column (numbers 1, 2, 3...): ATOM 1 N GLY A 1 -3.198 27.537 -5.958 1.00 0.00 N ATOM 2 CA GLY A 1 -2.199 28.399 -6.617 1.00 0.00 ... (3 Replies)
Discussion started by: tomasl
3 Replies

3. Shell Programming and Scripting

Sort and extract based on two files

Hi, I am having trouble sorting one file based on another file. I tried the grep -f function and failed. Basically what I have is two files that look like this: File 1 (the list) gh aba for hmm File 2 ( the file that needs to be sorted) aba 2 4 6 7 for 2 4 7 4 hmm 1 ... (3 Replies)
Discussion started by: phil_heath
3 Replies

4. Shell Programming and Scripting

Sort and extract based on two files

Hi, I am having trouble sorting one file based on another file. I tried the grep -f function and failed. Basically what I have is two files that look like this: File 1 (the list) gh aba for hmm File 2 ( the file that needs to be sorted) aba 2 4 6 7 for 2 4 7 4... (4 Replies)
Discussion started by: phil_heath
4 Replies

5. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

6. Shell Programming and Scripting

How to sort files based on file name having numbers

Right now there is no unix direct commad that can sort the files base on its name having numbers: We can use the following: In case your file name are like: abc-UP018.zip xyz-UP019.zip ls *|sort -t'-' -k2 (2 Replies)
Discussion started by: asifansari
2 Replies

7. Shell Programming and Scripting

How to sort the files according to the number?

Hi Everyone, I have a question: I have a lot of file named like or10000.dat, or9100.dat, or100.dat, or3100.dat... I want to deal with these files according to the number in the name. So I want to deal with or100.dat first and then or3100.dat and so on. I used : for i in `ls or*.dat |... (11 Replies)
Discussion started by: wxuyec
11 Replies

8. Shell Programming and Scripting

Sort the file based on number of occurences

I have a file (input) I want to sort the file based on the number of times a pattern in the first column occurs for example grapes occurs 4 times in combination with other patterns so i want it to be first like shown in the output file. then apple ocuurs thrice so it occupies second position and so... (7 Replies)
Discussion started by: anurupa777
7 Replies

9. Shell Programming and Scripting

Sort file based on number of delimeters in line

Hi, Need to sort file based on the number of delimeters in the lines. cat testfile /home/oracle/testdb /home /home/oracle/testdb/newdb /home/oracle Here delimeter is "/" expected Output: /home/oracle/testdb/newdb /home/oracle/testdb /home/oracle /home (3 Replies)
Discussion started by: Sumanthsv
3 Replies

10. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies
All times are GMT -4. The time now is 07:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy