Sorting 2 positional fields


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sorting 2 positional fields
# 1  
Old 02-01-2008
Question Sorting 2 positional fields

Hi Friends,

I've a large datafile, I've to sort the entire records of this file based on the positions. For ex:

ccc112IVEAGH VETERINARY SERVICES
cca110SHOOTER PROPERTY SERVICES
bbb111JUNIOR GOLF ACADEMY LIMITED
aaa110AULD PROPERTIES T/A R&J AULD
ccb111LISBURN FUELS
aac112P & MRS C LE ROUX T/A CURVES
bbc112ENNISKILLEN LAWN TENNIS CLUB
aab111BALLYDOWN KIDS ACADEMY LTD
bba110ROYAL ULSTER AGRICULTURAL SO


The above records have to be sorted from the position 1-3 and 4-6(This is only example, position may differ). I know how to sort records for one field using "sort" command. But positionwise and for two fields I dont know.
The expected result should be:

aaa110AULD PROPERTIES T/A R&J AULD
aab111BALLYDOWN KIDS ACADEMY LTD
aac112P & MRS C LE ROUX T/A CURVES
bba110ROYAL ULSTER AGRICULTURAL SO
bbb111JUNIOR GOLF ACADEMY LIMITED
bbc112ENNISKILLEN LAWN TENNIS CLUB
cca110SHOOTER PROPERTY SERVICES
ccb111LISBURN FUELS
ccc112IVEAGH VETERINARY SERVICES


Please help me

Thanks in advance / Mysore Ganapati
# 2  
Old 02-01-2008
Try
Code:
 sort -k1,3 -k4,6 YourFile

Thanks
Nagarajan G
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sorting on fields for last date

Hi all, I have a file with a list of rpm's that have different dates. I am trying to just grab the latest rpm and install date, and discard the rest. The file has 1000's of entries all with different names and dates. I have tried sort -k on the file and I am not grabbing the info, ... (4 Replies)
Discussion started by: gartie
4 Replies

2. Shell Programming and Scripting

[Solved] Sorting by several fields

Hello, I have a file with information separated by ";" like this: ABC;20110126000008;00-10-95-29-17-C6;2;37190292 ABC;20110126000008;00-10-95-29-17-C6;1;53140866 ABC;20110126000008;00-10-05-01-11-38;2;11182251 ABC;20110126000008;00-10-05-01-11-38;1;25952816... (3 Replies)
Discussion started by: rubber08
3 Replies

3. Shell Programming and Scripting

AWK multiple line fields sorting

I have a bash script which takes a log file with each record separated by a #. The records have multiple fields but field $1 is always the date and time. When the script is run it prints the record just fine from oldest to newest. I need to have records print out from newest first. Here is the... (7 Replies)
Discussion started by: numele
7 Replies

4. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

5. UNIX for Dummies Questions & Answers

Positional Parameters

Can someone tell me in more layman's terms what positional parameters are and give a good example? My book again is confusing me. :confused: (1 Reply)
Discussion started by: Straitsfan
1 Replies

6. Shell Programming and Scripting

sorting(both Ascending & Descending) files based on multiple fields

Hi All, I am encountered with a problem while sorting a file based on multiple columns . I need to sort like: (field2,ascending) , (field3,ascending) ,(field8,descending) , (field7,ascending),(field13,ascending). So far i was sorting only in ascending order but here i need to use one... (1 Reply)
Discussion started by: apjneeraj
1 Replies

7. UNIX for Dummies Questions & Answers

sorting fields of a line

Hi all, I have a file that looks like this... ########## 1zz2_15-43 1ouy_0-13-35 1.12619901947 2gfs_41-7 1yqj_3 0.793602121208 1bl7_11-3 1wbo_1-3-4 0.791065168287 1ywr_16-3 2ghl_22 0.956896171134 2exc_11-35 1pmq_13-15-87 0.597677672501 2bal_25-7 1ouk_17-19-21-228-58 0.668388304836... (6 Replies)
Discussion started by: Digby
6 Replies

8. Shell Programming and Scripting

ls positional parameter

Hi . I am new to Unix. So i have a tough time. we are using Korn Shell. I have a scenario where i have three files namely xxx01,xxx02,xxx03. Now when i write ls xxx*|wc -l output is 3. But then i write `ls $1|wc -l` and pass xxx* as positional parameter (sh yyy.sh xxx*) output is xxx01. other... (1 Reply)
Discussion started by: vasuarjula
1 Replies

9. AIX

ls positional parameter

Hi . I am new to Unix. So i have a tough time. we are using Korn Shell. I have a scenario where i have three files namely xxx01,xxx02,xxx03. Now when i write ls xxx*|wc -l output is 3. But then i write `ls $1|wc -l` and pass xxx* as positional parameter (sh yyy.sh xxx*) output is xxx01. other... (1 Reply)
Discussion started by: vasuarjula
1 Replies

10. UNIX for Dummies Questions & Answers

Sorting Compressed Fields

Are any of you guys aware of any problems when trying to sort compressed fields? Why I uncompress the file I am trying to sort, I have no problem sorting but when I try to sort compressed fields it doesnt work properly. I need to be able to sort these compressed fields. Any explanation why? (1 Reply)
Discussion started by: ndoggy020
1 Replies
Login or Register to Ask a Question