0

I have files in the following manner ar01440_1775_17_vc00_00.png ar01440_1775_17_vc00_01.png ar01440_1775_17_vc00_02.png ar01440_1775_17_vc00_03.png ar01440_1775_17_vc00_04.png ar01440_1775_17_vc00_05.png ar01440_1775_17_vc00_06.png ar01440_1775_17_vc00_07.png ar01440_1775_17_vc00_08.png ar01440_1775_17_vc00_09.png ar01440_1775_17_vc00_010.png ar01440_1775_17_vc00_011.png ar01440_1775_17_vc00_012.png ar01440_1775_17_vc00_013.png ar01440_1775_17_vc00_014.png ar01440_1775_17_vc00_015.png ar01440_1775_17_vc00_016.png ar01440_1775_17_vc00_017.png ar01440_1775_17_vc00_018.png ar01440_1775_17_vc00_019.png

I need to sort them into this order.

Desired output: ar01440_1775_17_vc00_00.png ar01440_1775_17_vc00_01.png ar01440_1775_17_vc00_010.png ar01440_1775_17_vc00_011.png ar01440_1775_17_vc00_012.png ar01440_1775_17_vc00_013.png ar01440_1775_17_vc00_014.png ar01440_1775_17_vc00_015.png ar01440_1775_17_vc00_016.png ar01440_1775_17_vc00_017.png ar01440_1775_17_vc00_018.png ar01440_1775_17_vc00_019.png ar01440_1775_17_vc00_02.png ar01440_1775_17_vc00_03.png ar01440_1775_17_vc00_04.png ar01440_1775_17_vc00_05.png ar01440_1775_17_vc00_06.png ar01440_1775_17_vc00_07.png ar01440_1775_17_vc00_08.png ar01440_1775_17_vc00_09.png

  • Stack Exchange sites are not code writing services. – Rob Jan 31 at 15:07
2

Using the 'en_US.UTF-8' locale caused the the '010' to appear before '01' when sorting. Forcing the C locale for the sort works here:

$ LC_ALL=C ls -1
ar01440_1775_17_vc00_00.png
ar01440_1775_17_vc00_01.png
ar01440_1775_17_vc00_010.png
ar01440_1775_17_vc00_011.png
ar01440_1775_17_vc00_012.png
ar01440_1775_17_vc00_013.png
ar01440_1775_17_vc00_014.png
ar01440_1775_17_vc00_015.png
ar01440_1775_17_vc00_016.png
ar01440_1775_17_vc00_017.png
ar01440_1775_17_vc00_018.png
ar01440_1775_17_vc00_019.png
ar01440_1775_17_vc00_02.png
ar01440_1775_17_vc00_03.png
ar01440_1775_17_vc00_04.png
ar01440_1775_17_vc00_05.png
ar01440_1775_17_vc00_06.png
ar01440_1775_17_vc00_07.png
ar01440_1775_17_vc00_08.png
ar01440_1775_17_vc00_09.png

The C locale is explained here: What does “LC_ALL=C” do?

  • 1
    May be worth noting that the * glob would sort this way too and that reading the output from ls is not really recommended (this is what I'm assuming that the user will do in the next step of whatever they're doing). – Kusalananda Jan 31 at 14:36
  • Stack Exchange sites are not code writing services. – Rob Jan 31 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.