Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svn status | sort - does not sort the output

I would like to sort svn status output, but somehow this command

svn status | sort

does not sort the output. Do you have any idea why?

for instance:

$ svn status 
?       idrd
?       core.7319
?       difftest
?       core.29328
A  +    rf_common/ext_api.sav
D       rf_common/ext_api/firewall_defs.h
D       rf_common/ext_api/rf_macro.h
?       firewall/src/hash2tuple.cpp.sav
!       firewall/src/hash2tuple.cpp
M       main.cpp
M       makefile

$ svn status | sort
A  +    rf_common/ext_api.sav
?       core.29328
?       core.7319
?       difftest
D       rf_common/ext_api
D       rf_common/ext_api/firewall_defs.h
D       rf_common/ext_api/rf_macro.h
!       firewall/src/hash2tuple.cpp
?       firewall/src/hash2tuple.cpp.sav
?       idrd
M       main.cpp
M       makefile

the question marks are not sorted, for instance.

like image 595
Ran Regev Avatar asked Nov 18 '13 10:11

Ran Regev


1 Answers

It seems that you want sort to disable last-resort comparison.

Saying

sort -s -k1,1

for your input would yield:

!       firewall/src/hash2tuple.cpp
?       idrd
?       core.7319
?       difftest
?       core.29328
?       firewall/src/hash2tuple.cpp.sav
A  +    rf_common/ext_api.sav
D       rf_common/ext_api/firewall_defs.h
D       rf_common/ext_api/rf_macro.h
M       main.cpp
M       makefile

Quoting man sort:

   -s, --stable
          stabilize sort by disabling last-resort comparison

From sort invocation:

Finally, as a last resort when all keys compare equal, sort compares entire lines as if no ordering options other than --reverse (-r) were specified. The --stable (-s) option disables this last-resort comparison so that lines in which all fields compare equal are left in their original relative order.

like image 149
devnull Avatar answered Oct 13 '22 00:10

devnull