Hello, have tried with awk not sort, because further processing has to be done to arrange files numerically correctly.
Please help.
musica 1 00
musica 5 00
musica 10 00
musicb 2 00
musicb 18 00
...
Code: Select all
ar0="musica 10 00.mp3\nmusica 10 01.mp3\nmusica 8 00.mp3\nmusica 8 01.mp3\nmusicb 11 00.mp3\nmusicb 11 01.mp3\nmusicb 2 00.mp3\nmusicb 2 01.mp3\nmusicb 5 00.mp3\nmusicb 5 01.mp3"
# complete script 1 wrong order
echo -e "$ar0" | awk -v y=-1 -v x=-1 '{match($0, /([ 0-9]+[.][m][p][3])/, w); $2=substr(w[1], 2, RLENGTH-5); $1=substr($0, 1, length($0)-(length($2)+8));
# split numbers /↑\
if($1==c){y++} else{y=0; x++}; a[x,y]=$1; b[x,y]=$2} {c=$1}
# sort array different names /↑\
END{for(v=0; v<=x; v++){for(u=0; u<=y; u++){d[b[v,u]]=a[v,u]};
# merge array /↑\
PROCINFO["sorted_in"]="@val_num_desc"; for(t in d){print d[t]"-"t; delete d[t]}}}
# sort output /↑\'
# complete script 2 wrong order
echo -e "$ar0" | awk -v y=-1 '{match($0, /([ 0-9]+[.][m][p][3])/, w); $2=substr(w[1], 2, RLENGTH-5); $1=substr($0, 1, length($0)-(length($2)+8));
if(a!=$1){y++}; b[y,$2]=$1} {a=$1}
END{PROCINFO["sorted_in"]="@val_num_desc"; for(x in b){split(x, c, SUBSEP); print b[c[1],c[2]]" "c[2] } }'
# error because different array length
echo -e "a 1\na 5\na 10\na 0\nb 0\nb 10\nb 5" | awk '{PROCINFO["sorted_in"]="@val_num_desc";
if(a!="" && a!=$1){for(z in b){print b[z]"-"z }; a=""}; b[$2]=$1} {a=$1}
ENDFILE{for(z in b){print b[z]"-"z}}'[\CODE]