![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strange sed behaviour | vino | UNIX for Advanced & Expert Users | 8 | 02-12-2008 03:51 AM |
| A Strange Behaviour!!! | navojit dutta | Shell Programming and Scripting | 5 | 12-21-2007 01:35 AM |
| a strange message when executing the sort command | marwan | UNIX for Dummies Questions & Answers | 3 | 04-27-2007 04:32 AM |
| Help me to resolve uncertian behaviour of a sort command | pankajrai | Shell Programming and Scripting | 1 | 12-21-2005 11:12 AM |
| /etc/passwd strange behaviour! | penguin-friend | Linux | 0 | 06-06-2005 09:00 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
Using option g?
Code:
sort -t";" -k 2,2rg file.to.sort |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
@ripat
Nope doesn't work - check the second column when having the ":" as delimeter. It only sorts the 1st number in front of the 1st ":". @miwinter Hm, I tested it with mawk on Debian Linux and on AIX with awk and no duplicate output. Not sure what you have to add to supress the duplicates... if you find no option to tell it awk, maybe pipe it into "uniq" at the end. |
|
#10
|
|||
|
|||
|
Or split the input to make it easier for sort to parse the fields you want.
Code:
vnix$*awk -F';' '{ split($2,t,":"); print t[1] ";" t[2] ";" t[3] ";" $0 }' <<HERE |
> GleamMIPostCanadaExtractJob;9196:53:12
> GleamMIAGREERepAllBackOutJob;9025:39:12
> GleamMIAGREEProdFacilCombJob;9025:29:36
> GleamMIAGREEExcRateHistExtractJob;9025:21:26
> GleamMIAGREEDynamicParamJob;9025:19:10
> GleamMIAGREEClassPODLoadJob;9025:09:43
> GleamMIAGREEClassExtractJob;9025:11:35
> GLMLRP_Diff_HighlighterJob;989:08:56
> GLMLRP_ComparisonJob;989:13:42
> AD046;988:44:15
> HERE
> sort -t ';' -rn | cut -d ';' -f4-
GleamMIPostCanadaExtractJob;9196:53:12
GleamMIAGREERepAllBackOutJob;9025:39:12
GleamMIAGREEProdFacilCombJob;9025:29:36
GleamMIAGREEExcRateHistExtractJob;9025:21:26
GleamMIAGREEDynamicParamJob;9025:19:10
GleamMIAGREEClassExtractJob;9025:11:35
GleamMIAGREEClassPODLoadJob;9025:09:43
GLMLRP_ComparisonJob;989:13:42
GLMLRP_Diff_HighlighterJob;989:08:56
AD046;988:44:15
|
|
#11
|
|||
|
|||
|
sort has a strange behavior. When you pipe him the second field using awk, the sort is ok:
Code:
$ awk -F";" '{print $2}' f | sort -rn
9196:53:12
9025:39:12
9025:29:36
9025:21:26
9025:19:10
9025:11:35
9025:09:43
989:13:42
989:08:56
988:44:15
Code:
$ sort -t";" -k2rn f GleamMIPostCanadaExtractJob;9196:53:12 GleamMIAGREEClassExtractJob;9025:11:35 GleamMIAGREEClassPODLoadJob;9025:09:43 GleamMIAGREEDynamicParamJob;9025:19:10 GleamMIAGREEExcRateHistExtractJob;9025:21:26 GleamMIAGREEProdFacilCombJob;9025:29:36 GleamMIAGREERepAllBackOutJob;9025:39:12 GLMLRP_ComparisonJob;989:13:42 GLMLRP_Diff_HighlighterJob;989:08:56 AD046;988:44:15 |
|
#12
|
|||
|
|||
|
And one more...
Forgot about that you can use more than one Field Separator - so here a more compact version (ok, some cheating on the delimiters with sed in the end): Code:
awk -F ";|:" 'BEGIN{OFS=":"} {print $1,$2,$3,$4}' infile| sort -t ":" -rn -k 2,2 -k 3,3 -k 4,4 | sed -n 's/\:/\;/p'
Btw, funny awards on your site |
|
#13
|
|||
|
|||
|
Got it! I had to read all possible options, even the one that are not well documented!
Code:
$ sort -t";" -s -k2,2rn f GleamMIPostCanadaExtractJob;9196:53:12 GleamMIAGREERepAllBackOutJob;9025:39:12 GleamMIAGREEProdFacilCombJob;9025:29:36 GleamMIAGREEExcRateHistExtractJob;9025:21:26 GleamMIAGREEDynamicParamJob;9025:19:10 GleamMIAGREEClassExtractJob;9025:11:35 GleamMIAGREEClassPODLoadJob;9025:09:43 GLMLRP_ComparisonJob;989:13:42 GLMLRP_Diff_HighlighterJob;989:08:56 AD046;988:44:15 Code:
Finally, as a last resort when all keys compare equal (or if no ordering options were specified at all), `sort' compares the entire lines. The last resort comparison honors the `-r' global option. The `-s' (stable) option disables this last-resort comparison so that lines in which all fields compare equal are left in their original relative order. If no fields or global options are specified, `-s' has no effect. |
|
#14
|
|||
|
|||
|
Nice solution!
Edit: Just saw that sort does not have that switch on AIX (didn't look for a similar one) but on Linux, nice though |
|||
| Google The UNIX and Linux Forums |