doubt in sort command!!!
5 posters
doubt in sort command!!!
wat is the option used in sort cmnd to sort based on a particular key???
xxx 23 63
yyy 24 72
zzz 25 70
aaa 27 75
$sort -n student
xxx 23 63
zzz 25 70
yyy 24 72
aaa 27 75
here the sorting is done based on field 3 contents defaultly,,,can we change this???if so,,,how???
xxx 23 63
yyy 24 72
zzz 25 70
aaa 27 75
$sort -n student
xxx 23 63
zzz 25 70
yyy 24 72
aaa 27 75
here the sorting is done based on field 3 contents defaultly,,,can we change this???if so,,,how???
Abhiramy- Posts : 9
Points : 21
Join date : 2010-02-26
Re: doubt in sort command!!!
sort -k1 student
this wud sort records based on the 1st field values
this wud sort records based on the 1st field values
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: doubt in sort command!!!
sort -k1n -k2 student
this sorts student using 2nd column values as major key and 1st as minor key
this sorts student using 2nd column values as major key and 1st as minor key
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: doubt in sort command!!!
sort -k1n -k2 student
What does dis exactly do? Can u explain dis wit an example pls?
What does dis exactly do? Can u explain dis wit an example pls?
Saradha Kannan- Posts : 25
Points : 25
Join date : 2010-03-04
Re: doubt in sort command!!!
if u want to use '|' as delimiter, try this command.
- Code:
$ sort -t '|' -k2 student
Re: doubt in sort command!!!
cat student
akalya 21 f
shiva 22 m
deva 23 m
maithreyi 22 f
sort -k1 student
akalya 21 f
deva 23 m
maithreyi 22 f
shiva 22 m
sort -k3 -k1n student
akalya 21 f
maithreyi 22 f
shiva 22 m
deva 23 m
@sarada it initially sorts using field3 as key then uses this output to sort fields based on field 2 values
hope u get it!!
akalya 21 f
shiva 22 m
deva 23 m
maithreyi 22 f
sort -k1 student
akalya 21 f
deva 23 m
maithreyi 22 f
shiva 22 m
sort -k3 -k1n student
akalya 21 f
maithreyi 22 f
shiva 22 m
deva 23 m
@sarada it initially sorts using field3 as key then uses this output to sort fields based on field 2 values
hope u get it!!
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: doubt in sort command!!!
thanks to all!!!its workin!!
Abhiramy- Posts : 9
Points : 21
Join date : 2010-02-26
Re: doubt in sort command!!!
@akalya : Thanks.. got it
Saradha Kannan- Posts : 25
Points : 25
Join date : 2010-03-04
prbs ! minor key not working!
hey
[336474@oracleclient ~]$ cat student
ganesh|21|07|m|
dinesh|22|05|m|
usha|23|42|f|
malthi|22|35|f|
preeti|22|12|f|
paru|22|40|f|
madhu|22|33|m|
[336474@oracleclient ~]$ sort -t '|' -k4n -k2 student
ganesh|21|07|m|
dinesh|22|05|m|
preeti|22|12|f|
madhu|22|33|m|
malthi|22|35|f|
paru|22|40|f|
usha|23|42|f|
i wanted to sort using second col as major key and 4th col as minor key!
but its sorting 2nd as major and 3rd col as minor key how come its possible?? or is the syntax wrong?
[336474@oracleclient ~]$ cat student
ganesh|21|07|m|
dinesh|22|05|m|
usha|23|42|f|
malthi|22|35|f|
preeti|22|12|f|
paru|22|40|f|
madhu|22|33|m|
[336474@oracleclient ~]$ sort -t '|' -k4n -k2 student
ganesh|21|07|m|
dinesh|22|05|m|
preeti|22|12|f|
madhu|22|33|m|
malthi|22|35|f|
paru|22|40|f|
usha|23|42|f|
i wanted to sort using second col as major key and 4th col as minor key!
but its sorting 2nd as major and 3rd col as minor key how come its possible?? or is the syntax wrong?
Permissions in this forum:
You cannot reply to topics in this forum
|
|