Help with sort list of file based on similarity


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with sort list of file based on similarity
# 1  
Old 04-28-2012
Help with sort list of file based on similarity

Input file (long list of input file):
Code:

s_1_1_AABCD.txt 
s_1_1_ABADA.txt 
s_1_1_DSCBA.txt 
s_1_1_DSCCA.txt 
s_1_1_EATTG.txt 
s_1_1_FADSD.txt 
s_1_1_TGACC.txt 
s_1_1_TTAGG.txt 
s_1_2_AABCD.txt 
s_1_2_ABADA.txt 
s_1_2_DSCBA.txt 
s_1_2_DSCCA.txt 
s_1_2_EATTG.txt 
s_1_2_FADSD.txt 
s_1_2_TGACC.txt
s_1_2_TTAGG.txt

Desired output file:
Code:
s_1_1_AABCD.txt 
s_1_2_AABCD.txt 
s_1_1_ABADA.txt 
s_1_2_ABADA.txt 
s_1_1_DSCBA.txt 
s_1_2_DSCBA.txt 
s_1_1_DSCCA.txt 
s_1_2_DSCCA.txt 
s_1_1_EATTG.txt 
s_1_2_EATTG.txt 
s_1_1_FADSD.txt 
s_1_2_FADSD.txt 
s_1_1_TGACC.txt 
s_1_2_TGACC.txt
s_1_1_TTAGG.txt 
s_1_2_TTAGG.txt

Command that I tried:
Code:
ls *.txt | sort -t_ -k4n
s_1_1_TTAGG.txt 
s_1_2_TTAGG.txt 
s_1_1_ABADA.txt 
s_1_2_ABADA.txt 
s_1_1_AABCD.txt 
s_1_2_AABCD.txt 
s_1_1_FADSD.txt 
s_1_2_FADSD.txt 
s_1_1_DSCBA.txt 
s_1_1_TGACC.txt 
s_1_2_DSCBA.txt 
s_1_2_TGACC.txt 
s_1_1_EATTG.txt 
s_1_2_EATTG.txt 
s_1_1_DSCCA.txt 
s_1_2_DSCCA.txt

I plan to sort the list of input file name in ascending order (from A to Z)
and s_1_1_* is followed by s_1_2_* when they share the same *

Thanks for any advice.

Last edited by perl_beginner; 04-28-2012 at 12:00 PM..
# 2  
Old 04-28-2012
-n is undesired in your case. Try:
Code:
ls *.txt | sort -t_ -k4

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to align/sort the column pairs of an csv file, based on keyword word specified in another file?

I have a csv file as shown below, xop_thy 80 avr_njk 50 str_nyu 60 avr_irt 70 str_nhj 60 avr_ngt 50 str_tgt 80 xop_nmg 50 xop_nth 40 cyv_gty 40 cop_thl 40 vir_tyk 80 vir_plo 20 vir_thk 40 ijk_yuc 70 cop_thy 70 ijk_yuc 80 irt_hgt 80 I need to align/sort the csv file based... (7 Replies)
Discussion started by: dineshkumarsrk
7 Replies

2. Shell Programming and Scripting

Sort based on positions in flat file

Hello, For example: 12........6789101112..............20212223242526..................50 ( Positions) LName FName DOB (Lastname starts from 1 to 6 , FName from 8 to 15 and date of birth from 21 to29) CURTIS KENNETH ... (5 Replies)
Discussion started by: duplicate
5 Replies

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

4. UNIX for Dummies Questions & Answers

Sort Files based on the number(s) on the file name

Experts I have a list of files in the directory mysample1 mysample2 mysample3 mysample4 mysample5 mysample6 mysample7 mysample8 mysample9 mysample10 mysample11 mysample12 mysample13 mysample14 mysample15 (4 Replies)
Discussion started by: dsedi
4 Replies

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

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

Not able to sort a file based on it name. Need your expert comments.

Hi, I have a files as shown below and I wanted to sort then in following patter based on there names which has "_" in it. I want to sort them according to feild 6th (bold once)value as shown below. Thanks in advance. File names: 20111014_manish_STEP2_Files_number__5979-6968_ ... (5 Replies)
Discussion started by: manishkomar007
5 Replies

8. Shell Programming and Scripting

Help with merge data based on similarity

Input_file data1 USA 100 ASE data3 UK 20 GWQR data4 Brazil 40 QWE data2 Scotland 60 THWE data5 USA 40 QWERR Reference_file USA 12312 34532 1324 Brazil 23321 231 3421 Scotland 342 34235 UK 231 141 England... (1 Reply)
Discussion started by: patrick87
1 Replies

9. Shell Programming and Scripting

Sort file based on column

Hi, My input file is $cat samp 1 siva 1 raja 2 siva 1 siva 2 raja 4 venkat i want sort this name wise...alos need to remove duplicate lines. i am using cat samp|awk '{print $2,$1}'|sort -u it showing raja 1 (3 Replies)
Discussion started by: rsivasan
3 Replies

10. Shell Programming and Scripting

Execution problem with sort the file based on contents

My input file: >ali ASSDDGHFHFHJFJHJDSDGSDGSDGSDGSDGSDGSDGDSGDSGSDGDSGSDGSDGDSGSDGGDSG >zzz ASdASDASDSADSADDSADJKHJDSADKLJADKLSAJDLJLKJLDASDDSADd >abu ASDASDFSAFASFSADFASDASDSADSADSADSADSADSADASDASdSADSADSADA >aaa... (2 Replies)
Discussion started by: patrick87
2 Replies
Login or Register to Ask a Question