How to sort lines based on a sub string in the line How to sort lines based on a sub string in the line shell shell

How to sort lines based on a sub string in the line


Use the following command

sort -n -t = -k 2 your_file

gives me

alex@rhyme ~ $ ash$ cat <<EOF | sort -n -t = -k 2> aaa=12> bbb=124> cccc=1> dddd=15> EOF cccc=1aaa=12dddd=15bbb=124$ which sort/usr/bin/sort$ LANG=C sort --versionsort (GNU coreutils) 8.21Copyright (C) 2013 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.Written by Mike Haertel and Paul Eggert.

Check the sort manpage for other sort options


sed -e 's/=\(.*\)$/=000000\1_\1/;s/=0*\([0-9]\{7\}\)_/=\1_/' YourFile | sort | sed -e 's/=[0-9]_/=/'

prepare for a basic sort not numeric nor taking column than put back in original form