[Vorbis] [sorta offtopic] Removing bad bytes from filenames

Chris Harrington (Personal) webkid at webkid.com
Mon Aug 20 13:16:40 PDT 2007


Chris Harrington (Personal) wrote:
> I'm having trouble moving my complete collection over because dbPowerAmp 
> (an application I used to love) made some dumb decisions about naming my 
> files. For example, in track/album/artist names that contained a 
> question mark ("O Brother, Where Art Thou?") it would insert the octal 
> byte 0277; an upside-down question mark.
> [blah blah blah...]

So awk hadn't yet occurred to me until I wrote that email. Here's a 
basic awk script that takes care of the problem (it's naive, and it 
doesn't *solve* the problem; it just makes the problem *solvable*) to be 
used in conjunction with the -b option of ls.

<script language="gawk">
/\\0/ { printf("mv %s", $0); gsub(/\\0/, "OCTAL0"); printf(" %s\n", $0); }
/\\1/ { printf("mv %s", $0); gsub(/\\1/, "OCTAL1"); printf(" %s\n", $0); }
/\\2/ { printf("mv %s", $0); gsub(/\\2/, "OCTAL2"); printf(" %s\n", $0); }
/\\3/ { printf("mv %s", $0); gsub(/\\3/, "OCTAL3"); printf(" %s\n", $0); }
</script>

This way, when you're trying to fix filenames using "rename", you can type

$ rename ThouOCTAL277 Thou *.ogg

to handle the issue intelligently.

To run, pipe in ls -b on the files you're examining, like this:
$ ls -b *.ogg | awk -f findBadOnes.awk > killoctal.sh

The "gsub" function requires "gawk/nawk", but I don't think anybody 
still runs old "awk".

-Chris


More information about the Vorbis mailing list