bash - POSIX "sort -n" alpha characters between zero and 1? -


i'm having trouble getting posix "sort" behave way want to. when sorting numeric file names, start letters show between 0 , 1.

why happen?

is there different sort option can use achieve desired result?

$touch 0 1 $ls | sort -n 

desired output: 0 1 a

actual output: 0 1

in gnu implementation, "-g" want, that's not posix. unfortunately, means can't use it.

if want explicitly sort output as

  • first numerically sorted files 0, 1, 2, 11, 222, , after
  • all other files sorted

you can example with

cat <(ls -1 | grep '^[0-9]' |sort -n) <(ls -1 | grep -v '^[0-9]' | sort) 

so catenate output of 2 commands

  • sort numerically files begins numbers, and
  • sort other files (what aren't begins numbers)

but, works bash , don't know how bash posix, if bash not ok can use temporary files...


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -