Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have this text:

menu.overlap.x: -7
menu.overlap.y: 0

!! Menu settings

menu.title.bg: Solid Flat
menu.title.bg.color: #fce855
menu.title.bg.colorTo: #daa30b
menu.title.bg.border.color: black
menu.title.text.color: #000000
menu.title.text.justify: left
menu.title.bg.interlace.color: #f5db14

!! General window settings
window.label.text.justify: center

!! focused window settings
window.active.client.color: #909498

If I paste it into LibreOffice Calc and use Data > Sort with the option of Range contains column labels unticked, I get this output:

!! focused window settings
!! General window settings
!! Menu settings
menu.overlap.x: -7
menu.overlap.y: 0
menu.title.bg: Solid Flat
menu.title.bg.border.color: black
menu.title.bg.color: #fce855
menu.title.bg.colorTo: #daa30b
menu.title.bg.interlace.color: #f5db14
menu.title.text.color: #000000
menu.title.text.justify: left
window.active.client.color: #909498
window.label.text.justify: center

I've tried sort with various options but I get this:

!! focused window settings
!! General window settings
menu.overlap.x: -7
menu.overlap.y: 0
!! Menu settings
menu.title.bg.border.color: black
menu.title.bg.color: #fce855
menu.title.bg.colorTo: #daa30b
menu.title.bg.interlace.color: #f5db14
menu.title.bg: Solid Flat
menu.title.text.color: #000000
menu.title.text.justify: left
window.active.client.color: #909498
window.label.text.justify: center

Which Linux command lets me sort the sample content in the same way as LibreOffice Calc does? (Blank lines are not important.)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This depends on your locale settings. Try this:

$ LC_ALL=C sort file




!! General window settings
!! Menu settings
!! focused window settings
menu.overlap.x: -7
menu.overlap.y: 0
menu.title.bg.border.color: black
menu.title.bg.color: #fce855
menu.title.bg.colorTo: #daa30b
menu.title.bg.interlace.color: #f5db14
menu.title.bg: Solid Flat
menu.title.text.color: #000000
menu.title.text.justify: left
window.active.client.color: #909498
window.label.text.justify: center

Or, to skip blank lines:

$ LC_ALL=C sort file | grep .
!! General window settings
!! Menu settings
!! focused window settings
menu.overlap.x: -7
menu.overlap.y: 0
menu.title.bg.border.color: black
menu.title.bg.color: #fce855
menu.title.bg.colorTo: #daa30b
menu.title.bg.interlace.color: #f5db14
menu.title.bg: Solid Flat
menu.title.text.color: #000000
menu.title.text.justify: left
window.active.client.color: #909498
window.label.text.justify: center
share|improve this answer
    
How do I know my locale settings? I'm quite happy otherwise so how do I change it just for sort, and for nothing else? Does LC_ALL=C do that? Where can I read more about LC_ALL=C? –  user15760 Jan 27 at 16:46
    
@vasa1 yes, basically, the format variable=value command will change the value of the variable only for the specific command. So what I am suggesting will affect only the current run of sort. For more info on LC_ALL, see here. –  terdon Jan 27 at 16:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.