<p>Using the same <strong>sort</strong> command with the same input produces different results on different machines.  How do I fix that?</p>

[{'answer_id': 28893, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 3, 'selected': False, 'text': "<p>This can be the result of locale differences:</p>\n\n<pre><code>$ echo 'CO2_\nCO_' | env LC_ALL=C sort\nCO2_\nCO_\n\n\n$ echo 'CO2_\nCO_' | env LC_ALL=en_US sort\nCO_\nCO2_\n</code></pre>\n\n<p>Setting the LC_ALL environment variable to the same value should correct the problem.</p>\n"}, {'answer_id': 28901, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 2, 'selected': False, 'text': '<p>This is probably due to different settings of the <a href="http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.nls/doc/nlsgdrf/locale_env.htm" rel="nofollow noreferrer">locale environment variables</a>. <code>sort</code> will use these settings to determine how to compare strings. By setting these environment variables the way you want before calling <code>sort</code>, you should be able to force it to behave in one specific way.</p>\n'}, {'answer_id': 28903, 'author': 'Henrik Gustafsson', 'author_id': 2010, 'author_profile': 'https://Stackoverflow.com/users/2010', 'pm_score': 6, 'selected': True, 'text': '<p>The <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/sort.1.html" rel="nofollow noreferrer">man-page</a> on OS X says:</p>\n<blockquote>\n<p>*******  WARNING ******* The locale specified by the environment affects sort order.  Set LC_ALL=C to get\nthe traditional sort order that uses native byte values.</p>\n</blockquote>\n<p>which might explain things.</p>\n<p>If some of your systems have no locale support, they would default to that locale (C), so you wouldn\'t have to set it on those. If you have some that supports locales and want the same behavior, set <code>LC_ALL=C</code> on those systems. That would be the way to have as many systems as I know do it the same way.</p>\n<p>If you don\'t have any locale-less systems, just making sure they share locale would probably be enough.</p>\n<p>For more canonical information, see The Single UNIX ® Specification, Version 2 description of <a href="http://opengroup.org/onlinepubs/007908799/xbd/locale.html" rel="nofollow noreferrer">locale</a>, <a href="http://opengroup.org/onlinepubs/007908799/xbd/envvar.html" rel="nofollow noreferrer">environment variables</a>, <a href="http://opengroup.org/onlinepubs/007908799/xsh/setlocale.html" rel="nofollow noreferrer">setlocale()</a> and the description of the <a href="http://opengroup.org/onlinepubs/007908799/xcu/sort.html" rel="nofollow noreferrer">sort(1)</a> utility.</p>\n'}, {'answer_id': 29315, 'author': 'Jörg W Mittag', 'author_id': 2988, 'author_profile': 'https://Stackoverflow.com/users/2988', 'pm_score': 2, 'selected': False, 'text': '<p>For more than you ever wanted to know about <code>sort</code>, read the <a href="http://OpenGroup.Org/onlinepubs/009695399/utilities/sort.html" rel="nofollow noreferrer" title="sort">specification of <code>sort</code></a> in the <a href="http://OpenGroup.Org/onlinepubs/009695399/" rel="nofollow noreferrer" title="Single Unix Specification v3">Single Unix Specification v3</a>. It states</p>\n\n<blockquote>\n  <p>Comparisons [...] shall be performed using the collating sequence of the current locale.</p>\n</blockquote>\n\n<p>IOW, how <code>sort</code> sorts is dependent on the locale (language) settings of the environment that the script is running under.</p>\n'}]
['https://Stackoverflow.com/questions/28881', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1438/']