bash - multi character separated sort -


how can sort !! delimited records using sort command?

for file1

1!!2!!3 2!3!!3!!1 3!!2!!2 

expected output

2!3!!3!!1 3!!2!!2    1!!2!!3 

then

sort -t \!\! -k 3 file1 

result:

sort: multi-character tab ‘!!’ 

why isn't working?

multi-character delimiters not allowed in sort -t can use:

sort -t '!' -k1 file 1!!b!!c 2!!f!!w 4!!e!!e 

edit: if ! can there in data can use trick:

sed 's/!!/\x06/g' file | sort -t $'\x06' -k1 | sed 's/\x06/!!/g' 1!!b!!c 2!!f!!w 4!!e!!e 

edit2: doing in single command use awk:

awk -f '!!' -v k=1 '{a[$k,$0]=$0}     end{asort(a, b, "@ind_num_asc"); (i in b) print b[i]}' file 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -