1

I have a great script that I use to convert encoding in srt.files. I also created an alias for that script so I can enter the directory where I want to run the script and use my alias konvert.

However, I have now the the following scenario: more then 20 directories with srt.files inside. What should I do in order to point my script to all those directories with just one command?

Luckily all these directories are together inside one main directory, so I believe there should be an easy way to do this.

Content of the script

#!/bin/bash for file in *.srt; do iconv -f CP1250 -t UTF-8 -o "$file".utf "$file" && mv "$file".utf "$file"; done 
  • @Zanna My script (I posted the code in my question) works great to convert .srt files when I cd into the directory where the files are stored. But I coudn't find the way to do that from a root directory that contains other directories with .srt files. Firstly I thought that I would find a way by taking advantage of that script but in the end it comes out that the better and moste effective solution is by using a different command. That's why, ultimately, I accepted the solution in the answer with command recode. It really did the job. – Dunav Rajna Feb 2 '18 at 8:53
3

Easy enough to accomplish without your script by using the following command line (using the application recode rather than straight iconv) which should be run from the root directory of your srt files:

find . -name '*.srt' -type f -exec bash -c 'recode -v CP1250..UTF-8 "$0"' {} \;

The command line searches recursively for all srt files and when each is found recode works on each file to change character encoding from CP1250 to UTF-8. With recode the encoding alteration does not require the clumsy filename shifting required by iconv...

How cool is the command line :)

| improve this answer | |
  • Thank you, @andrew.46 your altered answer with the command recode did a better job than my last variation with command iconv. Although I had to install recode it was worth it! :) – Dunav Rajna Feb 2 '18 at 8:04
  • @DunavRajna This is great news! And I see as well that the askubuntu community has reopened your question so extra great news :) – andrew.46 Feb 2 '18 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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