2
I tried other scripts I found online (*os I found), but to no avail. So I want to know some of you(s) how to do this automated/recursive task.
Shell Script Taken from: https://tsgii.blogspot.com/
set meta-flag on
set output-meta on
set convert-meta off
#!/bin/bash
NOMBRES_FICHEROS=$(ls)
for i in $NOMBRES_FICHEROS
do
echo '...TRATANDO EL FICHERO: '$i'...'
cat $i | tr [:upper:] [:lower:] > def_$i
cat $i | tr "ÁÉÍÓÚÑ" "AEIOUN" > def_$i
mv def_$i $i
done
No comments, it didn’t work! Maybe I don’t have Mr. Bash as CLI command interpreter
Shell Script Taken from: http://www.alexandrepinheiro.com/2011/05/shell-script-para-retirar-os-acentos.html
#!/bin/bash
for file in *;
do
newname=`echo "$file" | iconv -t 'ascii//TRANSLIT'`
mv "$file" "$newname"
done
This other one I found also did not run on my system, I think that could not even the interpreter Bash, only Ash linked to Bash.
Shell Script Taken from: https://www.vivaolinux.com.br/topico/Shell-Script/Remover-caracteres-esquisitos/
#!/bin/sh
for i in *
do
# ^ Quando esse chapeuzinho aparece no início de uma lista de caracteres significa negação;
j=`echo "$i" | sed 's/[^A-Za-z0-9_.]//g'`
# Vai remover todos os acentos das letras indicadas - https://www.vivaolinux.com.br/topico/Shell-Script/Script-para-retirar-acentos
j=`echo "$j" | sed 'y/áÁàÀãÃâÂéÉêÊíÍóÓõÕôÔúÚçÇ/aAaAaAaAeEeEiIoOoOoOuUcC/'`
mv "$i" "$j"
echo "Acento(s) removido de: $i"
done
This has already worked in parts, I say this, because the amendment makes a somewhat strange exchange, even changes characters without accent also [where there is no].
These are the ones I found.
To identify your shell, utilize
echo $SHELL
– Valdeir Psr
As I wrote before editing, please check. Anything I can remove and edit later.
– Valdeir Psr
@Diegohenrique I added an example with the
/bin/sh
– Valdeir Psr
I tested but when running the command which iconv discovered that I do not have and I did not find in the repository of the system Slitaz 5. A pity, since it could work. But for what it’s worth!
– Diego Henrique
Valdeirpsr can suggest @Diegohenrique to compile libiconv himself, first download at https://ftp.gnu.org/pub/gnu/libiconv/ --- extract the chosen .tar.gz, then navigate to the folder with the extracted content and execute:
./configure --prefix=/usr/local
,make
andmake install
. PS: I did not test– Guilherme Nascimento
@Guilhermenascimento I saw your suggestion, but it would be interesting something retro-compatibility [something you already have in virtually every operating system]
/bin/sh
– Diego Henrique
@Guilhermenascimento As I tried ->
$ ls -w1 *.txt | while read line; do mv "$line" "$(echo $line | tr 'ÁÉÍÓÚÑ' 'AEIOUN')"; done
– Diego Henrique
@Guilhermenascimento To rename several files you can use one
loop
, to enter the subfolders you would have to change the commandls
forfind
. The commandrename
uses the same syntax regex ofsed
, but you can manage without it if you need to...mv
does not work at all because of spaces in names, errors. So it is necessary to remove spaces ->$ for i in *.txt; do mv "$i" "
echo $i | tr ' ' '_'"; done
– Diego Henrique
@Diego and Valdeir, I assure you one thing, iconv (or libs equivalent) do not exist by chance, want to do in hand no
ÁÉÍÓÚÑ => AEIOUN
can work if you are sure of the CODEC, understand that theÁ
utf-8 is not the same thing asÁ
latin1 (window-1252, iso-8859-1 and equivalent/approximate), iconv detects coding, can even try to create something in hand, but it will be much more complex than a single line, probably will have to enumerate all possible variations of codecs, create something to remove permanently if codec is not supported [...]– Guilherme Nascimento
[...] , when it reaches a level of complexity so maybe the best is to use what already exists, to embark a software for this, to create something in [tag:c] or [tag:c++] own and so solve once and for all with something guaranteed to avoid codec problems.
– Guilherme Nascimento
I agree with @Guilhermenascimento. I downloaded the operating system (OS) and saw that it is quite simple (less than 50MB the live-cd version). In some tests with
sed
,awk
,tr
etc. You even have a simple result, but it is not what you expect. If you want something simpler, you can install theperl
and make a script basic. If you plan to install this ONLY on several devices, you can maintain a version withdocker
.– Valdeir Psr
@Guilhermenascimento Grateful for your beautiful explanation, I also agree with what you say. I also noticed this, the varied "codification". For now I’m using
iconv
in the distro Cdlinux-0.9.7.1 the same brings this tool with it, besides being a distro Live-CD and USB, can be installed side-by-side of Windows OS. In my case I had a way to manually install in the hard drive. For now, this serving me very well, aliases have been using it for a long time. From it, I useiconv
in it and I will think later on to elaborate a universal shell script, to give account task where there is noiconv
– Diego Henrique