# the third parameter defines the mode: 0 - append, 1 - prepend
cleandup() {
out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{ \\
- na = split(\$2,a,":"); \\
- if ( \$1 == "<empty>") nb = split("",b,":"); \\
- else nb = split(\$1,b,":"); \\
- s = "" ; \\
- for(i=1;i<=nb;i++) { \\
- if(!(b[i] in ccc)) { \\
- if(length(s)!=0) \\
- s = sprintf("%s:",s); \\
- s = sprintf("%s%s",s,b[i]); \\
- ccc[b[i]]; \\
- }; \\
- }; \\
- s1 = ""; \\
- for(i=1;i<=na;i++) { \\
- if(!(a[i] in ccc)) { \\
- if(length(s1)!=0) \\
- s1 = sprintf("%s:",s1); \\
- s1 = sprintf("%s%s",s1,a[i]); \\
- ccc[a[i]]; \\
- }; \\
- }; \\
- if(dir) \\
- s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\
- else \\
- s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\
- printf("%s\n",s); \\
- }'\`
+ na = split(\$2,a,":"); \\
+ k1=0; \\
+ bbb[k1++]=""; \\
+ ccc[""]; \\
+ if(\$1 != "<empty>") { \\
+ nb = split(\$1,b,":"); \\
+ for(i=1;i<=nb;i++) { \\
+ if(!(b[i] in ccc) ) { \\
+ ccc[b[i]]; \\
+ bbb[k1++]=b[i]; \\
+ }; \\
+ }; \\
+ }; \\
+ k2=0; \\
+ aaa[k2++]=""; \\
+ for(i=1;i<=na;i++) { \\
+ if(!(a[i] in ccc)) { \\
+ ccc[a[i]]; \\
+ aaa[k2++]=a[i]; \\
+ }; \\
+ }; \\
+ ORS=":"; \\
+ if(dir) { \\
+ for(i=1;i<k2;i++) { \\
+ print aaa[i]; \\
+ } \\
+ for(i=1;i<k1;i++) { \\
+ print bbb[i]; \\
+ } \\
+ } \\
+ else { \\
+ for(i=1;i<k1;i++) { \\
+ print bbb[i]; \\
+ } \\
+ for(i=1;i<k2;i++) { \\
+ print aaa[i]; \\
+ } \\
+ } \\
+ }' | sed -e 's/\(.*\):/\1/g'\`
echo \$out_var
}
### exporta ###
# the third parameter defines the mode: 0 - append, 1 - prepend
alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3 \\\\
'"'{ na = split(\$2,a,":"); \\\\
- nb = split(\$1,b,":"); \\\\
- s = "" ; \\\\
- for(i=1;i<=nb;i++) { \\\\
- if(!(b[i] in ccc)) { \\\\
- if(length(s)!=0) \\\\
- s = sprintf("%s:",s); \\\\
- s = sprintf("%s%s",s,b[i]); \\\\
- ccc[b[i]]; \\\\
- }; \\\\
- }; \\\\
- s1 = ""; \\\\
- for(i=1;i<=na;i++) { \\\\
- if(!(a[i] in ccc)) { \\\\
- if(length(s1)!=0) \\\\
- s1 = sprintf("%s:",s1); \\\\
- s1 = sprintf("%s%s",s1,a[i]); \\\\
- ccc[a[i]]; \\\\
- }; \\\\
- }; \\\\
- if(dir) \\\\
- s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\\\
- else \\\\
- s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\\\
- printf("%s\n",s); \\\\
- }'"'"
+ k1=0; \\\\
+ bbb[k1++]=""; \\\\
+ ccc[""]; \\\\
+ if(\$1 != "<empty>") { \\\\
+ nb = split(\$1,b,":"); \\\\
+ for(i=1;i<=nb;i++) { \\\\
+ if(!(b[i] in ccc) ) { \\\\
+ ccc[b[i]]; \\\\
+ bbb[k1++]=b[i]; \\\\
+ }; \\\\
+ }; \\\\
+ }; \\\\
+ k2=0; \\\\
+ aaa[k2++]=""; \\\\
+ for(i=1;i<=na;i++) { \\\\
+ if(!(a[i] in ccc)) { \\\\
+ ccc[a[i]]; \\\\
+ aaa[k2++]=a[i]; \\\\
+ }; \\\\
+ }; \\\\
+ ORS=":"; \\\\
+ if(dir) { \\\\
+ for(i=1;i<k2;i++) { \\\\
+ print aaa[i]; \\\\
+ } \\\\
+ for(i=1;i<k1;i++) { \\\\
+ print bbb[i]; \\\\
+ } \\\\
+ } \\\\
+ else { \\\\
+ for(i=1;i<k1;i++) { \\\\
+ print bbb[i]; \\\\
+ } \\\\
+ for(i=1;i<k2;i++) { \\\\
+ print aaa[i]; \\\\
+ } \\\\
+ } \\\\
+ }'"' | sed -e 's/\(.*\):/\1/g'"
### setenva ###
# appends directory or set of directories, separated by ':' (second parameter)
# to the variable (first parameter)