Convert numbers and spaces from full-width (double-byte) to half-width (single-byte) #


Within filenames (using Bash, Perl, and Unicode-Japanese-0.47):
  1. $sudo perl -MCPAN -e shell
  2. cpan> install Unicode::Japanese
  3. Save the following script (adapted largely from togdon's example) as full2half.sh and make it executable (chmod u+x):
    #!/bin/bash
    for file in *;do
    newfile=$(echo $file | perl -MUnicode::Japanese -e'print Unicode::Japanese->new(<>)->z2h->get;')
    test "$file" != "$newfile" && mv "$file" "$newfile"
    done
  4. cd to desired directory and run script:
    $ /path/to/full2half.sh
    Convert full-width numbers and spaces to half-width
Within file contents (using OpenOffice.org):
  1. Tools > Options... (in OS X it's OpenOffice.org > Preferences...)
  2. Language Settings > Languages > check "Enabled for Asian languages" > OK
  3. Highlight text > Format > Change Case > Full-width or Half-width

/nix | Jan 02, 2010


Subscribe or visit the archives.