Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 2200  / 1 Year ago, sat, march 25, 2023, 12:19:19

I think the ideal solution for me is a Nautilus Script that performs encoding conversion on selected files.



The following script reads the encoding of a selected file and performs utf8 conversion if it's not utf8, but I couldn't figure out how to make it work on multiple files:



CHARSET="$(file -bi "$1"|awk -F "=" '{print $2}')"
if [ "$CHARSET" != utf-8 ]; then
iconv -f "$CHARSET" -t utf8 "$1" -c -o "$1.utf8"
fi

More From » conversion

 Answers
7

Let's say your script is named convert-to-utf-8.sh. Here's how you would make it work across multiple files:



for filename in file1 file2 file3 ; do ./convert-to-utf-8.sh "$filename" ; done


You could incorporate that for-loop in the script itself, like this:



for filename in "$@"; do
CHARSET="$(file -bi "$filename"|awk -F "=" '{print $2}')"
if [ "$CHARSET" != utf-8 ]; then
iconv -f "$CHARSET" -t utf8 "$filename" -c -o "$filename.utf8"
fi
done


You could then run the script with multiple filenames like this:



./convert-to-utf-8.sh file1 file2 file3

[#32831] Saturday, March 25, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leddre

Total Points: 180
Total Questions: 113
Total Answers: 108

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
;