Sort the filenames containing . in file name


 
Thread Tools Search this Thread
Top Forums Programming Sort the filenames containing . in file name
# 1  
Old 06-02-2010
Sort the filenames containing . in file name

Hi All,

I have a list of files in a directory ..which are look like:
42420031.1000
42420031.1001
42420031.396
42420031.402
42420031.403
42420031.404
42420031.405
42420031.406
42420031.407
42420031.408
42420031.409


Here when i do ls 42420031* |sort it gives the output as

42420031.1000
42420031.1001
42420031.396
42420031.402
42420031.403
42420031.404
42420031.405
42420031.406
42420031.407
42420031.408
42420031.409

which is incorrect;it should be
42420031.396
42420031.402
42420031.403
42420031.404
42420031.405
42420031.406
42420031.407
42420031.408
42420031.409
42420031.1000
42420031.1001

here problem is causing by character '.' and it interprets as dot(decimal)..
Can anybody pls help me to do this sorting right??

Many thanks for your help.

Regards,
Sanjay
# 2  
Old 06-02-2010
Code:
ls 42420031* |sort -n -k 1.10

# 3  
Old 06-02-2010
yet another way...
Code:
ls | sort -t. -k1,1n -k2n

# 4  
Old 06-10-2010
Hi Jim,

Thanks!!

This worked absolutely fine for me.

you guys are remarkable.


Many thanks again!

Regards,
Sanjay

---------- Post updated at 06:44 AM ---------- Previous update was at 06:43 AM ----------

Hi Shamrock,

Thanks!!

This also worked fine.
Many thanks again!

Regards,
Sanjay
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sort the filenames

Hello Unix experts: I have dir where few files are there, i want to sort these files and write the output to some other file but i need filenames with filepath too eg: i have filenames like 010020001_S-FOR-Sort-SYEXC_20171218_094256_0004.txt so i want to sort my files on first 5 fields of... (2 Replies)
Discussion started by: gnnsprapa
2 Replies

2. UNIX for Beginners Questions & Answers

How do I custom sort the files in a directory using the filenames in a text file.?

Hi all, (5 Replies)
Discussion started by: KMusunuru
5 Replies

3. 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

4. Shell Programming and Scripting

How to get filenames in a directory and write them in to a file?

I need to get the names of files which are starting with a string testfile. Also i want to create a XML file in the same location and write these file names into the XML. Ex: <path> <dir> <file>testfile1</file> </dir> <dir> <file>testfile2</file> </dir>... (4 Replies)
Discussion started by: vel4ever
4 Replies

5. UNIX for Dummies Questions & Answers

Capture filenames with a Pattern into another file

Hi i have a command in windows which captures the filenames with the same pattern and route it to another file. for example filetest_20110921, filetest_20110922,filetest_20110923 etc I would like to know the command in UNIX/LINUX for the same. The command which i am using in Windows is ... (12 Replies)
Discussion started by: mansurkhalil
12 Replies

6. Shell Programming and Scripting

Sort based on filenames

Hi All, When i give ls -ltr my filenames looks like this: Filename Pattern: Abc_Def_mmddyyyyHHmm.csv $ ls -ltr Jun 05 04:30 Abc_Def_060520111245.csv Jun 05 08:40 Abc_Def_071220121458.csv Jun 06 03:30 Abc_Def_071220111458.csv Jun 06 04:25 Abc_Def_060620110439.csv Jun 07 04:37... (12 Replies)
Discussion started by: HemaV
12 Replies

7. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

8. Shell Programming and Scripting

Copying filenames into a new file

I have about 35,000 files in one directory. Here I have to write a ksh to take only the filenames of 500 files at a time and put them into a new file. Can anyone please help me. Thank you. (8 Replies)
Discussion started by: vpv0002
8 Replies

9. AIX

How to grep filenames from a file in other files?

Hi, We have a file called applcust.txt where we keep records of our customizations in the following format. We want to verify whether the file, which is in 3rd column in this file is there in another file called patch999999.log to find out if any of our customization has got overwritten by the... (2 Replies)
Discussion started by: sshah1001
2 Replies

10. Shell Programming and Scripting

bash: reading filenames from file

Hi, I'm trying to write a script that reads filenames from a file and use these filenames in a loop. The filenames are all on one line and the problem is that these filenames have wildcards like * and braces like in them. Right now what I'm doing is something like this: echo "reading from... (0 Replies)
Discussion started by: warp17
0 Replies
Login or Register to Ask a Question