Skip to main content
deleted 69 characters in body
Source Link

Sorting Numbers with ls -v

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved with a combination of printf to add the decimal padding, and sed to later remove the padding.

Here's the code.

#!/usr/bin/env bash

# exit if tmp directory### alreadysort.sh exists###
[
tmpdir="$(mktemp -e /tmp/sort ] && echo d)"/tmp/sort already exists" && exit 1

mkdir /tmp/sort
cd /tmp/sort"${tmpdir}"

for num in "$@"; do
    touch "$(printf "%0.10f" "$num""${num}")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf /tmp/sort-- "${tmpdir}"

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124

Sorting Numbers with ls -v

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved with a combination of printf to add the decimal padding, and sed to later remove the padding.

Here's the code.

#!/usr/bin/env bash

# exit if tmp directory already exists
[ -e /tmp/sort ] && echo "/tmp/sort already exists" && exit 1

mkdir /tmp/sort
cd /tmp/sort

for num in "$@"; do
    touch "$(printf "%0.10f" "$num")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf /tmp/sort

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124

Sorting Numbers with ls -v

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved with a combination of printf to add the decimal padding, and sed to later remove the padding.

Here's the code.

#!/usr/bin/env bash

### sort.sh ###

tmpdir="$(mktemp -d)"

cd "${tmpdir}"

for num in "$@"; do
    touch "$(printf "%0.10f" "${num}")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf -- "${tmpdir}"

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124
added 36 characters in body
Source Link

Sorting Numbers with ls -v

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved with a combination of printf to add the decimal padding, and sed to later remove the padding.

Here's the code.

#!/usr/bin/env bash

# exit if tmp directory already exists
[ -e /tmp/sort ] && echo "/tmp/sort already exists" && exit 1

mkdir /tmp/sort
cd /tmp/sort

for num in "$@"; do
    touch "$(printf "%0.10f" "$num")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf /tmp/sort

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved with a combination of printf to add the decimal padding, and sed to later remove the padding.

Here's the code.

#!/usr/bin/env bash

# exit if tmp directory already exists
[ -e /tmp/sort ] && echo "/tmp/sort already exists" && exit 1

mkdir /tmp/sort
cd /tmp/sort

for num in "$@"; do
    touch "$(printf "%0.10f" "$num")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf /tmp/sort

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124

Sorting Numbers with ls -v

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved with a combination of printf to add the decimal padding, and sed to later remove the padding.

Here's the code.

#!/usr/bin/env bash

# exit if tmp directory already exists
[ -e /tmp/sort ] && echo "/tmp/sort already exists" && exit 1

mkdir /tmp/sort
cd /tmp/sort

for num in "$@"; do
    touch "$(printf "%0.10f" "$num")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf /tmp/sort

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124
Mod Removes Wiki by Shog9
added 51 characters in body
Source Link

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved usingwith a combination of printf to add the decimal padding, and later removed using sed to later remove the padding.

Here's the code.

#!/usr/bin/env bash

# exit if tmp directory already exists
[ -e /tmp/sort ] && echo "/tmp/sort already exists" && exit 1

mkdir /tmp/sort
cd /tmp/sort

for num in "$@"; do
    touch "$(printf "%0.10f" "$num")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf /tmp/sort

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved using printf, and later removed using sed.

Here's the code.

#!/usr/bin/env bash

# exit if tmp directory already exists
[ -e /tmp/sort ] && echo "/tmp/sort already exists" && exit 1

mkdir /tmp/sort
cd /tmp/sort

for num in "$@"; do
    touch "$(printf "%0.10f" "$num")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf /tmp/sort

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124

The ls program can be used to solve your problem. The -v flag can be used to do a natural sort of files by version numbers. Just create files that are named after the doubles, then use ls -v to output a sorted list of the doubles.

The file names need to all have the same number of decimals for the -v flag to work properly. This can be achieved with a combination of printf to add the decimal padding, and sed to later remove the padding.

Here's the code.

#!/usr/bin/env bash

# exit if tmp directory already exists
[ -e /tmp/sort ] && echo "/tmp/sort already exists" && exit 1

mkdir /tmp/sort
cd /tmp/sort

for num in "$@"; do
    touch "$(printf "%0.10f" "$num")"
done

ls -1v | sed 's/\.\?0\+$//g'

cd ..
rm -rf /tmp/sort

Example usage is below:

$ sort.sh 234 45 213 384.123 384.124 383 384.023
45
213
234
383
384.023
384.123
384.124
Source Link
Loading