Created
April 17, 2015 00:10
-
-
Save lavoiesl/b2270522ad1f2283c813 to your computer and use it in GitHub Desktop.
BASH sort by filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Sort all files by their filename, independently of their folder | |
# Example: ls -1 /a/* /b/* | sort_by_filename | |
# | |
# @input One path per line | |
# @outputs One path per line | |
function sort_by_filename() { | |
while read filename; do | |
echo "${filename}" | sed -E 's/^(.+)\/([^/]+)$/\2#\1\/\2/'; | |
done | sort -n | cut -d '#' -f 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment