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

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Praveen Kumar
  • 69
  • 2
  • 6

1 Answers1

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?

Haxiel
  • 8,361
  • 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 '19 at 14:36
  • Stack Exchange sites are not code writing services. – Rob Jan 31 '19 at 15:08