Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have files that had Slovak characters in them I copied them to my Ubuntu now they have these weird symbols in them, anyone knows how would I remove these character?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can take advantage of the iconv utility, able to convert a string from an character encoding to another, and to also perform transliteration to similar character, when the destination encoding miss them.

The following script will rename each file passed on the command line to an ascii version of the same name. Modify the variable input_enc if needed, and run with --no-test as first parameter to really rename.

#!/bin/bash

input_enc="UTF-8"

test=1
if [[ $1 == '--no-test' ]]; then
  test=0
  shift
else
  echo "This is a simulation"
  echo "run with --no-test as first parameter to really rename"
  echo
fi

normalize() {
  local f="$1"
  echo "$f" | iconv -f "$input_enc" -t ASCII//TRANSLIT
}

for f; do
  g="$(normalize "$f")"
  if ((test)); then
      echo mv -i "$f" "$g"
  else
      mv -i "$f" "$g"
  fi
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.