jthill, I've applied your snippet of code in a script combined with Nominal Animal's test for valid UTF-8:
Code:
#/bin/bash
echo "THIS IS A TEST";
LIST=`ls /my/test/files`;
echo "THIS IS A TEST TOO";
for i in $LIST
do
if !(iconv -f UTF-8 -t UTF-8 $i &>/dev/null) ;
then
echo "$i is not valid UTF-8"
ex -b -u NONE -c 'set backup' -c '/^<body>$/,/^<\/body>$/!iconv -f windows-1252 -t utf-8' -c 'wq' "$i"
fi
done
I am getting back some errors:
Code:
[xxx@abc123 bashScripts]# bash TESTbash2
THIS IS A TEST
THIS IS A TEST TOO
100525ED.htm.bak is not valid UTF-8
"100525ED.htm.bak" [New File]
Error detected while processing command line:
E486: Pattern not found: ^<body>$
"100525ED.htm.bak" [New File] 0 lines, 0 characters written
100601ED.htm is not valid UTF-8
"100601ED.htm" [New File]
Error detected while processing command line:
E486: Pattern not found: ^<body>$
"100601ED.htm" [New File] 0 lines, 0 characters written
[xxx@abc123 bashScripts]#
My backups are in the script directory, I think, instead of the source directory. But they are empty files.
I have one reference for bash, 3rd Edition O'Reilly Linux in a Nutshell. I see no reference to the 'set backup' in the options for 'set'. I also don't see -b or -u as options for the 'ex' command. Is my reference too old?
Despite the errors, the script works and I hope to advance it to search and change sub-directories. What is the significance of the errors?