How to sort multiples clolumns of a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to sort multiples clolumns of a file?
# 1  
Old 06-20-2003
How to sort multiples columns of a file?

Hi all!

here is the file i am trying to sort :

GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:04
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:16
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:11
GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:06
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:25
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:21
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:04:35
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:05:03
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:19:56
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:03
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:05
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:20:00
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:27:39
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:34
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:37
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:28:23
...


As you can all notice...it is a real mess....
I aim to obtain the following result Smilie :


GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:04
GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:06
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:11
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:16
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:21
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:25
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:04:35
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:05:03
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:19:56
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:20:00
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:03
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:05
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:34
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:37
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:28:23
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:27:39


I guess i must use the "sort" command...but it really seems very tricky...

Can someone help me on this one?

thanks!

Regards,

Howard

Last edited by HowardIsHigh; 06-20-2003 at 09:53 AM..
# 2  
Old 06-20-2003
Are you SURE you want the file to end up that way???

It does not seem like it's sorted. Portions of it are, but then you throw a curve in the middle:

First few lines: Sorted:
GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:04
GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:06
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:11
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:16
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:21

Next two lines: Not Sorted:
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:25
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18

Next few lines: Sorted:
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:04:35
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:05:03
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:19:56
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:20:00
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:03
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:05
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:34
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:37

Next two: Not Sorted:
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:28:23
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:27:39

If you want them sorted - try
$ sort -t\; -k 1,2 -k 3,4 -k 5 inputfile
# 3  
Old 06-20-2003
Yeah true,

sorry about that....i sorted it roughly...

here is what i wish to obtain :

GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:04
GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:06
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:11
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:16
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:21
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:25
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:04:35
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:05:03
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:19:56
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:20:00
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:03
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:05
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:34
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:37
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:27:39
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:28:23

anyway thank you very much for your answer...i'll try it on monday and keep you in touch.

cheers

howard
# 4  
Old 06-21-2003
Its working! Its Working !!

Thank you very much !

Smilie Smilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add line numbers (multiples of 5: 0,5,10,15,20) to a text file?

Hi, I need to number the lines in my text file. I know how to do this with standard numbering (1,2,3,4, etc) but I need to count in multiples of 5, beginning 0,5,10,15... example existing file: abcd efg hijklm nopqrs desired output 0 abcd 5 efg 10 hijklm 15 ... (11 Replies)
Discussion started by: livbaddeley
11 Replies

2. UNIX for Dummies Questions & Answers

Separate file into multiples Linux

Hi guys I am newbie in using linux, how can i Separate file into multiples linux. I want the lines with same parent and id numbers print out into same files. For example Gm17 5135289 5136789 . Parent=533;ID=534;Name=Glyma17g07060 - Gm17 5135289 5136789 . ... (2 Replies)
Discussion started by: grace_shen
2 Replies

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

4. Shell Programming and Scripting

awk on multiples files

Ques from newbie I want to total column X from large number of files, and view totals for each file separately with the filename. I have tried: for i in `ls -1 *.pattern`; do cat "$i" | awk '{SUM += $4} END { printf("%8d\t%8d\n", $i,SUM) }'; done does not work. appreciate your help (5 Replies)
Discussion started by: analyst
5 Replies

5. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

6. Programming

multiples of 10 in java

Hi Guys, I wonder how can I determine when a given number is a multiple of another one in java. Let's say if I have 27 how can I determine whether is multiple of 5 using java programming. Thanks. (1 Reply)
Discussion started by: arizah
1 Replies

7. Shell Programming and Scripting

join multiples seds

Hi I have this string with 3 seds.. cat /tmp/roletmp|sed "s/$role2del//" | sed "s/,,/,/" |sed "s/^,//" |sed 's/,$//' How can I join these 3 seds in one? regards Israel. (3 Replies)
Discussion started by: iga3725
3 Replies

8. Shell Programming and Scripting

multiples menu in ksh

Hi, IS possible in ksh to make multiples menus? For example: My menu. 1)Option1 1.1)Option1.1 2.3)Option1.2 2)Option2 2.1)Option2.1 . . . x)Exit I've tried with case but no success. Thanks in advance. (3 Replies)
Discussion started by: iga3725
3 Replies

9. Programming

Pointer addresses in multiples of 32 ?

1. Why are the pointers' addresses every 32 ? 2. Am I correct in stating that memset is writing to memory that is not allocated to any of the 3 pointers ? Is it writing to memory in between the pointers ? 3. Are the 3 pointers contiguous in memory ? 4. I only allocated 10 bytes for each pointer.... (5 Replies)
Discussion started by: cyler
5 Replies

10. UNIX for Dummies Questions & Answers

Using cp for copying multiples files

Hi all, I've got this question about using cp for copying multiples files from the same source directory to another directory, considering that my working directory ain't the same of the source directory. Let me give you a simple example what I'm talking about: Suppose the following files... (2 Replies)
Discussion started by: chapeupreto
2 Replies
Login or Register to Ask a Question