# translate.awk --- do tr-like stuff # # Arnold Robbins, arnold@skeeve.com, Public Domain # August 1989 # February 2009 - bug fix # Bugs: does not handle things like tr A-Z a-z; it has # to be spelled out. However, if `to' is shorter than `from', # the last character in `to' is used for the rest of `from'. function stranslate(from, to, target, lf, lt, ltarget, t_ar, i, c, result) { lf = length(from) lt = length(to) ltarget = length(target) for (i = 1; i <= lt; i++) t_ar[substr(from, i, 1)] = substr(to, i, 1) if (lt < lf) for (; i <= lf; i++) t_ar[substr(from, i, 1)] = substr(to, lt, 1) for (i = 1; i <= ltarget; i++) { c = substr(target, i, 1) if (c in t_ar) c = t_ar[c] result = result c } return result } function translate(from, to) { return $0 = stranslate(from, to, $0) } # main program BEGIN { if (ARGC < 3) { print "usage: translate from to" > "/dev/stderr" exit } FROM = ARGV[1] TO = ARGV[2] ARGC = 2 ARGV[1] = "-" } { translate(FROM, TO) print }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
alarm.awk | File | 2.31 KB | 0644 |
|
anagram.awk | File | 1.33 KB | 0644 |
|
awksed.awk | File | 515 B | 0644 |
|
cut.awk | File | 3.61 KB | 0644 |
|
dupword.awk | File | 507 B | 0644 |
|
egrep.awk | File | 1.91 KB | 0644 |
|
extract.awk | File | 1.74 KB | 0644 |
|
guide.awk | File | 165 B | 0644 |
|
histsort.awk | File | 283 B | 0644 |
|
id.awk | File | 1.22 KB | 0644 |
|
igawk.sh | File | 3.11 KB | 0644 |
|
indirectcall.awk | File | 952 B | 0644 |
|
labels.awk | File | 1014 B | 0644 |
|
split.awk | File | 1.17 KB | 0644 |
|
tee.awk | File | 770 B | 0644 |
|
testbits.awk | File | 729 B | 0644 |
|
translate.awk | File | 1.15 KB | 0644 |
|
uniq.awk | File | 2.64 KB | 0644 |
|
wc.awk | File | 1.45 KB | 0644 |
|
wordfreq.awk | File | 347 B | 0644 |
|