1

I need to:

1) translate several txt (or pdf) files. They are saved in different folders in my notebook.

2) save the translated text in a new folder.

the best answer I could find on google in to use soimort, which translate a txt file.

Read on soimort:

Translate a File

Instead of using the -input option, a file URI scheme (file:// followed by the file name) can be used as a command-line argument:

$ trans :fr file://input.txt

My question is: how can I do the previous task using Ubuntu?

R. S.
  • 11

1 Answers1

0

Do it one file at a time? Unless it is lots and lots of files, looking at what you are doing is crucial.

If they live in dir1, dir2, and so on:

for d in dir1 dir2 dir3; do
   (cd $d; for f in `ls *.txt`; do frobnicate $f; done)
done

Explanation: The outer for walks over directories. In a subhell (the(...)) we enter the directory, grab the names of any *.txt files, frobnicate each of them in turn (the inner for), and we are done. As the inner job is in a subshell, we are back were we started, and can go to the next directory.

Careful, this will explode in your face if any directory or file name contains spaces or other funky characters. It doesn't save away the originals (in case frobnicate mangles their contents), and (obviously) will frobnicate any already frobnicated files it finds.

vonbrand
  • 18,253
  • My file name contains spaces. Is there a way to solve this problem? What is the problem with spaces? – R. S. Mar 05 '20 at 21:27