Want to sort a file which contains alphanumeric strings


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Want to sort a file which contains alphanumeric strings
# 1  
Old 08-26-2013
Want to sort a file which contains alphanumeric strings

I want to sort a file which contains alphanumeric string.

Code:
bash-3.00$ cat abc
mtng1so
mtng2so
mtng11so
mtng9so
mtng23so
mtng7so
hstg2so
hstg9so
hstg1so
hstg11so
hstg13so
bash-3.00$

Want output like this, using one liner.

Code:
hstg1so
hstg2so
hstg9so
hstg11so
hstg13so
mtng1so
mtng2so
mtng7so
mtng9so
mtng11so
mtng23so

# 2  
Old 08-26-2013
If file contents are going to have the same rigid format i.e. the first 4 characters are alphabets then the below sort works...
Code:
sort -k1.1,1.4 -k1.5,1n file

This User Gave Thanks to shamrock For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort two columns with alphanumeric values horizontally

Hi, I have a file like aa bb dmns|860 dmns|756 ee ff aa bb dmns|310 dmns|260 ee ff aa bb dmns|110 dmns|77 ee ff aa bb dmns|756 dmns|860 ee ff aa bb dmns|110 dmns|77 ee ff aa bb dmns|233 dmns|79 ee ff aa bb dmns|79 dmns|233 ee ff I want to sort the values in column3 and column4... (2 Replies)
Discussion started by: sammy777888
2 Replies

2. Shell Programming and Scripting

Sort strings containing numbers

How can I sort this, first by 2nd field then by 1st field. tried sort -b -k 2,2 Input: AS11 AB1 BD34 AB10 AF12 AC2 A345 AB10 R134 AB2 456 AC10 TTT2 BD12 desired output: AS11 AB1 R134 AB2 A345 AB10 BD34 AB10 AF12 AC2 456 AC10 TTT2 BD12 (2 Replies)
Discussion started by: aydj
2 Replies

3. Shell Programming and Scripting

Sort strings with numbers

I want to sort my data first by the 2nd field then by the first field. I can't use sort -V because I don't have gnu sort and cannot install one. How do I go about this? Input: G456 KT1 34 K234 KT10 45 L2 KT2 26 H5 LAF2 28 F3 LAF2 36 Output: G456 KT1 34 L2 KT2 26 K234 KT10 45 F3... (14 Replies)
Discussion started by: aydj
14 Replies

4. Shell Programming and Scripting

Increment Column having Alphanumeric value in file

I want to replace a column(first and last) having an alphanumeric value in a file. Requirement : 1)All values in a Column must be unique and contain an incremented pattern “HCTV0096” for first column and “cafefeca0090” for last column 2)for uniquely identifying each value in column Numeric part... (6 Replies)
Discussion started by: ketanraut
6 Replies

5. Shell Programming and Scripting

Trouble with alphanumeric Sort

I have a lot of data that need to be sorted alphanumerically. I began using sort -du and it solved almost all my problems. However, when I encountered files with data like this it began to fail: /vol/close_eng_ice_0888 /vol/open_eng_ice_0890 /vol/open_eng_ice_08923 /vol/open_eng_ice_0893... (6 Replies)
Discussion started by: newbie2010
6 Replies

6. Shell Programming and Scripting

Sorting alphanumeric strings without a pattern

Good evening to all!! I'm facing this problem: I saved in a txt a list of files name (one txt for every folder): hello0.jpg hello1.jpg hello10.jpg hello11.jpg hello12.jpg hello13.jpg hello14.jpg hello15.jpg hello16.jpg hello17.jpg hello18.jpg hello19.jpg hello2.jpg hello20.jpg... (32 Replies)
Discussion started by: silver18
32 Replies

7. UNIX for Dummies Questions & Answers

How to sort lines by strings between ()?

Hello,everyone. I am learning some Info commands.I put all commands and their explanations in a file. This is a part of it: ESC PgUp (scroll-other-window-backward)Scroll the other window backward ESC Right (forward-word) Move forward a word ESC r (move-to-window-line) ESC TAB... (3 Replies)
Discussion started by: vic005
3 Replies

8. Programming

Sort ascending n strings in C

Hy guys. My English is not so good, sorry for any mistakes. I'm a bigginer in C, and I have a problem. I want to sort ascending n strings, but I can't read the strings. Here is what I've done so far: //sort ascending n strings #include <stdio.h> int main() { int n,i,j; char a; ... (8 Replies)
Discussion started by: 1/0
8 Replies

9. Shell Programming and Scripting

how to sort strings by length?

I'm trying to find the longest word in /usr/share/dict/words The first thing I can think of is to sort the content by length then it would be easy to find out, but then i realize theres no option of sort to sort by length. Could you guys please give me some help?:confused: (7 Replies)
Discussion started by: rockbike
7 Replies

10. Shell Programming and Scripting

sort command - alphanumeric

I have a file I'm trying to sort such as fred1 fred2 fred10 fred11 ... when I sort I get fred1 fred10 fred11 fred2 ... using sort can any give me the syntax to sort this is dict order e.g., (4 Replies)
Discussion started by: gefa
4 Replies
Login or Register to Ask a Question