unix SORT


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers unix SORT
# 1  
Old 03-19-2008
unix SORT

Hey guys.

I am trying to sort a file by account number through UNIX. I have a few things but it seems to sort by account number AND sort everything after the account number.

Help please.

Thanks
# 2  
Old 03-19-2008
Question

If you show what the input looks like and what the desired output should be then it would be easier to suggest something.
# 3  
Old 03-19-2008
How to handle non-unique data?

You said: "AND sort everything after the account number"
What do you want to have happen when similar records are found?

input=
002x
003d
001a
003a
001b

output from sort on acct # (first 3 positions)
001a
001b
002x
003a
003d
# 4  
Old 03-19-2008
The underlying problem seems to be that whenever it finds a match when its sorted. It compares additional data after the account number to see if they are equal. I want the sort to just ignore these two same account numbers and continue normally without looking at data past the account number field.
So in other words, how can I just ignore the two account numbers that match without having it look past the acct nbr?

Hope that makes sense.
# 5  
Old 03-19-2008
Question Really need to see sample input and desired output data

Quote:
So in other words, how can I just ignore the two account numbers that match without having it look past the acct nbr?
What do you mean by that? A sort re-orders data, so are you asking to 'delete' records that are not unique?

This is becoming confusing... so please just paste in some sample data.
# 6  
Old 03-19-2008
Run:

Code:
man sort

Check out the "-k (--key)" option. You can have it sort by just one field.

Here's an example of sorting by the second column of a comma-separated file:

Code:
 $ sort -t "," file.dat -k 2

If your file is currently separated by whitespace, you can ignore the whole -t bit and it should work just with the -k option.

Shawn
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX sort

Hi I have below pattern A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: pens 4 B:Bags 4 A: cells 6 A: jobs 6 Output I need : A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: cells 6 A: jobs 6 ... (7 Replies)
Discussion started by: pkkanduk
7 Replies

2. Shell Programming and Scripting

Issue with Sort in Unix

Hi All, I am trying to sort the below data using sort command. temp.dat H|S1-511091486889|27-Jul-2011 00:00:00 H|S1-511091486823|27-Jul-2011 00:00:00 H|S1-511091486757|27-Jul-2011 00:00:00 L|S1-511091486889|1 L|S1-511091486823|1 L|S1-511091486757|1 sort -t "|" -k2 -k1 temp.dat My... (5 Replies)
Discussion started by: deepaknbk
5 Replies

3. Shell Programming and Scripting

Sort with UNIX

I want to sort unique values of column 2 that has the maximum value at column 7. this is my file and desired output I have a file like this: AD008 AD0081010180947 101018 0947 0950 1010180947 1010180950 AD008 AD0081010180947 101018 0947 0956 1010180947 1010180956 AD008 AD0081010180947... (12 Replies)
Discussion started by: aydj
12 Replies

4. Shell Programming and Scripting

need Unix script to sort

Hi i have a file like this oprvdw vrc002093j.ksh oprvdw vrc002092j.ksh oprvrc vrc045016j.ksh oprvrc vrc055141j.ksh svemietl bdw0231185.sh svemietl bdw0231145.sh and i need a script which dispalys in below format: oprvdw : vrc002093j.ksh vrc002092j.ksh oprvrc :... (0 Replies)
Discussion started by: p_satyambabu
0 Replies

5. UNIX for Dummies Questions & Answers

UNIX sort command

Need some help with the sort command. I have a large file which needs sorted on the third field separated by : and within the third field, I need it sorted by second field or everything after the . An example of my file is here and for example, the first line I need :ROUTER2.SFLDMI: sorted on the... (2 Replies)
Discussion started by: numele
2 Replies

6. UNIX for Dummies Questions & Answers

using Unix sort command

Hi I am having some difficulties with the UNIX sort command. I want to sort one a file that looks like this (file A): tiger 5 6 3 5 2 bear 4 5 2 1 8 lions 9 2 5 3 1 dogs 8 5 3 3 1 acccording to a file that looks like this (file B): dogs lions tiger bear So... (2 Replies)
Discussion started by: phil_heath
2 Replies

7. UNIX for Dummies Questions & Answers

UNIX Sort question

I was trying to check for the sort of some columns (say 1-10) of particular file. Now, by default, the Unix sort uses as a separator whitespace (e.g. if you have 'foo bar' then it separates it into 'foo' and 'bar' to use as keys) Now, I know which particular columns I want to use as the sort... (1 Reply)
Discussion started by: rev.meister
1 Replies

8. Shell Programming and Scripting

SORT order in Unix

I am converting mainframes JCL to be used in shell on a one to one basis... when i use the sort command unix does ascii sort as a result which numbers are first followed by charecters in the Ascending sort ... but themainframes uses the EBCDIC as result gives the charecters followed by numbers in... (5 Replies)
Discussion started by: bourne
5 Replies

9. UNIX for Dummies Questions & Answers

Unix Sort - Limitations

Hi All, I want to sort a flat file which will contain millions of records based on a key/field. For this I want to use unix sort command and before that I want to make sure that unix sort command has any file size limitations. And also please let me know whether I have to change any... (2 Replies)
Discussion started by: chprvkmr
2 Replies

10. UNIX for Advanced & Expert Users

Unix Sort - Alternatives

Hi All, I want to sort a flat file which will contain millions of records based on a key/field. For this I want to use unix sort command and before that I want to make sure that unix sort command has any file size limitations. And also please let me know whether I have to change any... (1 Reply)
Discussion started by: chprvkmr
1 Replies
Login or Register to Ask a Question