Arranging files in order of files_digits


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Arranging files in order of files_digits
# 1  
Old 10-19-2012
Arranging files in order of files_digits

Hi all,
I have input files in some directory as:

Code:
$ ls -ltr
 -rw-r--r-- 1 emily us_cms 101614219 Oct  8 15:47 vgtree_197_0_7pV.root
-rw-r--r-- 1 emily us_cms 101348458 Oct  8 16:43 vgtree_518_0_LHB.root
-rw-r--r-- 1 emily us_cms 101386298 Oct  8 16:50 vgtree_291_0_cWd.root
-rw-r--r-- 1 emily us_cms 101551150 Oct  8 16:53 vgtree_289_0_JSf.root
-rw-r--r-- 1 emily us_cms 101348458 Oct  8 17:04 vgtree_518_0_YTs.root
-rw-r--r-- 1 emily us_cms 101481802 Oct  8 17:07 vgtree_251_0_N6T.root
-rw-r--r-- 1 emily us_cms 101309649 Oct  8 17:07 vgtree_198_0_bCn.root
-rw-r--r-- 1 emily us_cms 101349505 Oct  9 07:07 vgtree_575_0_6RT.root
-rw-r--r-- 1 emily us_cms 101716996 Oct  9 08:54 vgtree_517_1_sE7.root
-rw-r--r-- 1 emily us_cms 101423961 Oct  9 10:06 vgtree_122_0_7g2.root
-rw-r--r-- 1 emily us_cms 101473618 Oct  9 10:10 vgtree_187_0_aa1.root
-rw-r--r-- 1 emily us_cms 101481802 Oct  9 11:56 vgtree_251_0_Y2E.root
-rw-r--r-- 1 emily us_cms 101366281 Oct  9 14:17 vgtree_320_1_2me.root
-rw-r--r-- 1 emily us_cms 101632226 Oct  9 14:58 vgtree_240_1_E5S.root
-rw-r--r-- 1 emily us_cms 101852105 Oct  9 15:11 vgtree_501_0_z5T.root
-rw-r--r-- 1 emily us_cms 101283966 Oct  9 16:10 vgtree_257_1_tiq.root
-rw-r--r-- 1 emily us_cms 101600046 Oct  9 22:18 vgtree_281_1_WFP.root
-rw-r--r-- 1 emily us_cms 101372192 Oct  9 22:19 vgtree_317_1_TpA.root
-rw-r--r-- 1 emily us_cms 101558034 Oct  9 23:20 vgtree_265_1_OQN.root
-rw-r--r-- 1 emily us_cms 101460480 Oct 16 10:45 vgtree_256_1_UtH.root

I would like to view them in the following order for example,: in increasind order of the digits with the file name.
Code:
-rw-r--r-- 1 emily us_cms 101670480 Oct 16 10:45 vgtree_256_1_UtH.root
-rw-r--r-- 1 emily us_cms 101460450 Oct 16 10:45 vgtree_257_1_UtH.root
-rw-r--r-- 1 emily us_cms 101464580 Oct 16 10:45 vgtree_258_1_UtH.root
-rw-r--r-- 1 emily us_cms 101445480 Oct 16 10:45 vgtree_260_1_UtH.root

Thanks in advance,
emily,
# 2  
Old 10-19-2012
Code:
ls | awk -F_ '{print $2,$0}' OFS=\t | sort -n | cut -f2-

# 3  
Old 10-19-2012
Hi,
Thanks foe the quick reply.Smilie

But there is one problem, the output is in the form
Code:
 605tvgtree_605_0_Ooo.root
606tvgtree_606_0_Tm8.root
607tvgtree_607_0_g6x.root
608tvgtree_608_0_ZhB.root
609tvgtree_609_0_EzG.root
610tvgtree_610_0_7fB.root
611tvgtree_611_0_QBm.root
612tvgtree_612_0_zYY.root
613tvgtree_613_0_EfH.root

I would also like to have the file size information along with it. It is important for me. For example like this
Code:
  
101386298 tvgtree_612_0_zYY.root
101384568 tvgtree_613_0_EfH.root

I do not worry about the rest information about the date and all.


Thanks
Emily,
# 4  
Old 10-19-2012
Small change to vgersh99's solution...


Code:
ls -lt | awk -F_ '{print $3,$0}' OFS=\t | sort -n | cut -f2-

and try this also..

Code:
ls -lt | sort -k9

# 5  
Old 10-19-2012
I don't understand. If you want to sort by filename why do you use -rt option (sorted by reverse time) and not a simple :
Code:
ls -l

or if you want only size + filename :
Code:
find ./ -maxdepth 1 -printf '%s %f\n' | sort -k 2

# 6  
Old 10-19-2012
Dear vgersh99, Pamu and delugeag

Thanks for the reply, it worked fine.
Code:
 
$                                                                                                                
514t-rw-r--r-- 1 emily us_cms 101813022 Sep 30 16:15 vgtree_514_0_Gah.root
515t-rw-r--r-- 1 emily us_cms 101617328 Sep 30 15:59 vgtree_515_0_7tu.root
516t-rw-r--r-- 1 emily us_cms 101463547 Sep 30 15:59 vgtree_516_0_Vir.root
517t-rw-r--r-- 1 emily us_cms 101716996 Oct  9 08:54 vgtree_517_1_sE7.root
517t-rw-r--r-- 1 emily us_cms 101716996 Sep 30 16:01 vgtree_517_0_wcb.root
518t-rw-r--r-- 1 emily us_cms 101348458 Oct  8 16:43 vgtree_518_0_LHB.root
518t-rw-r--r-- 1 emily us_cms 101348458 Oct  8 17:04 vgtree_518_0_YTs.root
519t-rw-r--r-- 1 emily us_cms 101934101 Sep 30 15:56 vgtree_519_0_7Ik.root

But I just realized that it is not the end of my trouble. Actually, there are some 10k such files with double counting of some files. For example in the code above, it is "vgtree_518*.root" and "vgtree_517*root".

Now, what I need to do is to select such double (or triple) occurring files and delete the one having smaller file size. And would like to keep the one with the big file size.
Code:
518t-rw-r--r-- 1 emily us_cms 101348458 Oct  8 16:43 vgtree_518_0_LHB.root
518t-rw-r--r-- 1 emily us_cms 101348458 Oct  8 17:04 vgtree_518_0_YTs.root
518t-rw-r--r-- 1 emily us_cms 101348200 Oct  8 17:04 vgtree_518_0_YTs.root

Here in the code, I would like to keep any of the above 2 files as they have same file size and would like to delete the rest two.


I am not sure if it is doable using script. SmilieSmilie else, I will have to do it manually, Smilie



Thanks,
emily
# 7  
Old 10-19-2012
Quote:
Originally Posted by emily
Dear vgersh99, Pamu and delugeag

Thanks for the reply, it worked fine.
What worked fine? You were provided with multiple suggestions. Since you are seeking further refinements, knowing exactly what code you're currently using will save time.

Also, it always helps to know the operating system and shell being used.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Loop Through Files in Order and mapping

Hi there, How can I loop through files with order. I tried using ls .html | sort -v However the filename is with spaces:1233.61.47.0 - 121.61.123.112 nexpose.html Here is the original code that is working well, but I need to sort through the filename.echo "<center>" for file in *.html... (2 Replies)
Discussion started by: alvinoo
2 Replies

2. Shell Programming and Scripting

How to list files in ascending order?

Hi, I need to list files in ascending order. Filenames are in format inpTDT_1, inpTDT_2, inpTDT_3 and so on. I want to list them in the ascending order based on the digit after underscore and send the output to a file. Please help (5 Replies)
Discussion started by: Neelkanth
5 Replies

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

4. UNIX for Advanced & Expert Users

Uploading files in chronological order

Thanks for your help. (3 Replies)
Discussion started by: circuit.muni
3 Replies

5. UNIX for Advanced & Expert Users

merge two files in ascending order

Hello Friends, I want to merge two files in ascending order on the first field. And if the first field matches sort on 3rd field i.e, TXADDR should come ahead of RXADDR . file1 9 : TXADDR : 00000000 65 : TXDATA 0000000000000011 83 : TXDATA 0000000000000012 453 :... (10 Replies)
Discussion started by: user_prady
10 Replies

6. Shell Programming and Scripting

Arranging files

Hi all, This is program to identify and arrange programs(scripts) based on their she-bang values to a folder with the same name. The parts of mkdir and copy and creating problems.I also doubt the use of hash...maybe some problems in it. Please help out debugging this. Code pasted at: Paste... (2 Replies)
Discussion started by: Vivek788
2 Replies

7. Shell Programming and Scripting

Comparing files enen when they are not in order

Hi, I have two master files which contain the information for many jobs like this Job no:1 a b c d Job no:1 d e g h Job no:2 t j s h Job no:2 t j s h I have written a script to pick up all the information for Job no:1 from file1 and put that to a temporary file and do the same from... (2 Replies)
Discussion started by: ragavhere
2 Replies

8. UNIX for Dummies Questions & Answers

list of files in date order

Im on HP/UX and am trying to find the command like an ll but that will sort showing the most currently modified programs first. Can anyone help me with that? :cool: (2 Replies)
Discussion started by: Jeannine
2 Replies

9. Shell Programming and Scripting

Listing files in numerical order

Hi, I'm trying to write a ksh script to copy a specified number of files from one directory to another. The files are named in the convention <switchname>_log.<num> and the numbers are sequential single digit onwards. I figured I could find some parameter for ls which would list the files in... (3 Replies)
Discussion started by: Steve_H
3 Replies

10. UNIX for Advanced & Expert Users

lp - order of files printed

I have a shell script that is looping through a list of Postscript files to print. ls -1tr *.PS > print.lst ... PRINT_LIST=`cat print.lst` ... for DMFILE in $PRINT_LIST do lp -d $PRINTER_NAME -o legal $DMFILE ... done The files in print.lst are in the order that they should be... (2 Replies)
Discussion started by: mabrownawa
2 Replies
Login or Register to Ask a Question