List of multilingual files

hi,
I have in a directory a big number of files and their translation in other languages. A typical name of a file is xx_xxxx_EN.html and its translation xx_xxxx_IT.html . I want to extract a 2 column txt file with the names of the files. For example for the english - italian language pair:
xx_xxxx_EN.html xx_xxxx_IT.html

Do you have any idea?
Thank you in advance!

#!/bin/bash

for EN_file in *EN.html
do
        IT_file=$( echo "${EN_file}" | sed 's/_EN\.html/_IT\.html/g' )
        echo "${EN_file} ${IT_file}" >> output.txt
done
1 Like

Thank you for your reply, but it does not work. The output is:

*EN.html *EN.html
*EN.html *EN.html
*EN.html *EN.html

The file names are:
en_david_en.html
en_david_it.html
en_david_fr.html
fr_george_en.html
fr_george_it.html
...

The list that I want should be like:

en_david_en.html en_david_it.html
fr_george_en.html fr_george_it.html

Thank you in advance!

---------- Post updated at 05:37 PM ---------- Previous update was at 05:10 PM ----------

I changed your script and it works!!! Thank you!

#!/bin/bash

for EN_file in *.en.html
do
        IT_file=$( echo "${EN_file}" | sed 's/_\.en\.html/_\.it\.html/g' )
        echo "${EN_file} ${IT_file}" >> output.txt
done

You can also do this without calling the external sed command in bash like this:

#!/bin/bash

for EN_file in *en.html
do
        echo "${EN_file} ${EN_file/en.html/it.html}"
done > output.txt
1 Like

Unfortunately I tried to run the scripst but does not work. These scripts recplace the .en.html with the it.html. The problem is that There are files only in one language. For example the en_david_en.html is only in english and not it italian. I don't want this file in my list.
Thank you in advance.

If you don't want this file listed, then check if Italian file exists and write to o/p file:

#!/bin/bash

for EN_file in *en.html
do
        IT_file=$( echo ${EN_file/en.html/it.html} )
        [[ -f ${IT_file} ]] && echo "${EN_file} ${IT_file}" >> output.txt
done
1 Like

ok thank you! now it works!