How to sort alphanumeric numbers in the shell
1 answer
You can use:
awk -v OFS='\t' '{rec=$0; gsub(/[^[:digit:]]+/, "", rec); print rec, $0}' file
| sort -nk1 | cut -d $'\t' -f2-
bc14de
cd 18
abc90
100def
-
awk
used to add first column of input with numeric characters only withgsub
-
sort -nk1
used to sort input numerically in the first column -
cut
finally used to truncate the first column
+4
source to share