Custom sorting in shell -


i have custom order sorting: 'd','r' -> 'i' -> 'w','x' , 'z'. is, 'd' , 'r' equal , sort before 'i'; , 'w', 'x' , 'z' equal , sort after 'i'.

input:

123d123 234r111 333i333 111w111 222x222 111z111 

the sorting on 4th character, , followed sorting 5th 7th characters.

the expected output be:

234r111 123d123 333i333 111w111 111z111 222x222 

paste <(cut -c 4-7 file | tr 'rwx' 'dzz') <(cat file) | sort -k 1,1 | awk '{print $2}'  234r111 123d123 333i333 111w111 111z111 222x222 

explanation: create key r=d , w=x=z, sort key, discard key


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -