[TriLUG] Linux From Scratch
Cristóbal Palmer via TriLUG
trilug at trilug.org
Tue Mar 4 15:22:41 EST 2025
On Tue, Mar 4, 2025, at 14:02, via TriLUG wrote:
> Speaking of signal-to-noise ratio, here's a little bash script
I write for two reasons. The first is to iterate on your script to make it more cross-platform, and the second is to share an example URL that highlights (for me) the biggest flaw in the approach.
cmp at oof ~ % cat textsig.sh
#!/usr/bin/env bash
while [ ! -z $1 ]; do
htmlpage=$(curl --disable -sSL "$1")
if [ $? -ne 0 ]; then
echo "curl error"
exit 1
fi
htmlbytes=$(echo "$htmlpage" | wc -c)
echo "html bytes: $htmlbytes"
txtbytes=$(echo "$htmlpage" | html2text | wc -c)
echo "text bytes: $txtbytes"
echo -n "Signal ratio for "
# some platforms don't support 'echo -e' so we
# use printf here
printf "\033[1m\033[4m%s\033[0m\n" "${1}"
echo " $(echo "$txtbytes / $htmlbytes" | bc -l)"
unset htmlpage txtbytes htmlbytes
shift
done
cmp at oof ~ % ./textsig.sh https://www.flickr.com/photos/nasa2explore/
html bytes: 588455
text bytes: 4589
Signal ratio for https://www.flickr.com/photos/nasa2explore/
.00779838730234257504
Warmly,
CMP
More information about the TriLUG
mailing list