sort in unix [message #324072] |
Fri, 30 May 2008 11:09 |
pa1sas3
Messages: 29 Registered: June 2005
|
Junior Member |
|
|
I have to sort the input file on 4th field in
descending order and use sql loader to put in a
oracle table.
Each field separated by '|'
First field is the primary key.
So, I can load one row per primary key with
max value in the 4th field, ignoring order on other
fields
I have to accomplish this in UNIX on a file
that looks like below:
This is how the input file looks like:
ABCD-0000-01|Philadelphia|200103|HONDA|BRND
ABCD-0000-01|Philadelphia|200103|TOYOTA|BRND
ABCD-0000-01|Philadelphia|200103|SUBARU|BRND
ABCD-0000-01|New York|200103|SUBARU|BRND
ABCD-0000-02|.... next row set details
ABCD-0000-02|...
required sort Output should be:
ABCD-0000-01|Philadelphia|200103|TOYOTA|BRND
ABCD-0000-01|Philadelphia|200103|SUBARU|BRND
ABCD-0000-01|New York|200103|SUBARU|BRND
ABCD-0000-01|Philadelphia|200103|HONDA|BRND
So that, when I use SQL LOADER, only the
first row in put in table and rejecting the other
3 rows (first field is primary key).
I tried this:
sort -t'|' +0 -1 -r +3 -4 input.dat -o output.dat
But it is sorting the full file. How to sort only
on the 4th field in descending ignoring the rest?
Thanks,
Pavan
|
|
|
|
Re: sort in unix [message #324076 is a reply to message #324072] |
Fri, 30 May 2008 11:39 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
>I have to sort the input file on 4th field in descending order and use sql loader to put in a oracle table.
No you don't!
The order of the rows in an RDBMS table are indeterminate.
|
|
|