[Solved] Sorting by several fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Sorting by several fields
# 1  
Old 02-05-2011
[Solved] Sorting by several fields

Hello,
I have a file with information separated by ";" like this:
Code:
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
ABC;20110126000009;00-10-95-29-17-C6;2;37190292
ABC;20110126000009;00-10-95-29-17-C6;1;53140866

and i would like to be ordered by fields 3, 2 and 4 like:
Code:
ABC;20110126000008;00-10-05-01-11-38;1;25952816
ABC;20110126000008;00-10-05-01-11-38;2;11182251
ABC;20110126000008;00-10-95-29-17-C6;1;53140866
ABC;20110126000008;00-10-95-29-17-C6;2;37190292
ABC;20110126000009;00-10-95-29-17-C6;1;53140866
ABC;20110126000009;00-10-95-29-17-C6;2;37190292

Thanks,

bye

Last edited by Scott; 02-05-2011 at 06:46 AM.. Reason: Please use code tags
# 2  
Old 02-05-2011
Code:
$ sort -t\; -k3,3 -k2,2 -k4 file
ABC;20110126000008;00-10-05-01-11-38;1;25952816
ABC;20110126000008;00-10-05-01-11-38;2;11182251
ABC;20110126000008;00-10-95-29-17-C6;1;53140866
ABC;20110126000008;00-10-95-29-17-C6;2;37190292
ABC;20110126000009;00-10-95-29-17-C6;1;53140866
ABC;20110126000009;00-10-95-29-17-C6;2;37190292

# 3  
Old 02-06-2011
Thanks for all!!!!!!
Bye
# 4  
Old 02-06-2011
Mark it
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. UNIX for Dummies Questions & Answers

[Solved] Help correcting file with differing number of fields

Hi all, I have a tab separated file, and one of the fields is sub-delimited by colon. The problem is there can be zero to 4 colons within this field. When I try to change colons to tabs the result is a file with a differing number of fields. I want to go from: a:b:c:d:e a:b:c a:b:c:d:e a... (4 Replies)
Discussion started by: torchij
4 Replies

3. Shell Programming and Scripting

ip 2 country sorting[solved]

Dear folks. I have list of ip address from different country, i would like check from script this ip address belong to which country, please suggest any command, i have more than 200 ip address so i need to do it via script. Script will show me country code and its City if possible? ... (0 Replies)
Discussion started by: learnbash
0 Replies

4. Shell Programming and Scripting

[SOLVED] Sorting file and get everything on same line on condition

Good afternoon! I am a perl newbie. I hope you will be patient with me. I have a script that needs to be written in perl. I can't do it in awk or shell scripting. Here is the script: #!/usr/bin/perl use POSIX qw(strftime); use FileHandle; use Getopt::Long; use IO::Handle;... (0 Replies)
Discussion started by: brianjb
0 Replies

5. Shell Programming and Scripting

[SOLVED] Sorting into new files based on column

Hi, I have the following file, I need to sort it based on a column and write to different output files based on this column request_guid iso_country_cd address_data response_time 32895901-d17f-414c-ac93-3e7e0f5ec240 AND BaseName:CATALUNYA; HouseNumber:1; ISOCountryCode:AND;... (1 Reply)
Discussion started by: ramky79
1 Replies

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

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

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

9. UNIX for Dummies Questions & Answers

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... (1 Reply)
Discussion started by: ganapati
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