Use gnu sed if possible

This commit is contained in:
Rob Pearce 2023-12-01 15:08:32 +11:00
parent 799ba547ff
commit 391d137a21
1 changed files with 9 additions and 4 deletions

View File

@ -145,6 +145,10 @@ if [[ $# -ne 0 ]]; then
fi fi
SED=$(which gsed 2>/dev/null)
[[ $? -ne 0 ]] && SED=$(which sed 2>/dev/null)
[[ -z $SED ]] && fatal "can't find sed in path"
# Read config file # Read config file
if [[ ! -e ${CONFIG} || ! -f ${CONFIG} ]]; then if [[ ! -e ${CONFIG} || ! -f ${CONFIG} ]]; then
fatal "config file '$CONFIG' doesn't exist or isn't a plaintext file" fatal "config file '$CONFIG' doesn't exist or isn't a plaintext file"
@ -193,10 +197,11 @@ elif [[ $MODE == "test" ]]; then
url="${site_url[$idx]}" url="${site_url[$idx]}"
temp=$(newtempfile) temp=$(newtempfile)
curl -sL "$url" | sed 's/>/>\n/g;s/</\n</g;' | awk NF | egrep -v "^<.*>$" > ${temp}
curl -sL "$url" | ${SED} 's/>/>\n/g;s/</\n</g;' | awk NF | egrep -v "^<.*>$" > ${temp}
if [[ $TEST_USERES -eq 1 ]]; then if [[ $TEST_USERES -eq 1 ]]; then
sedcmd="/${site_re_start[$idx]}/,/${site_re_end[$idx]}/p" sedcmd="/${site_re_start[$idx]}/,/${site_re_end[$idx]}/p"
cat "$temp" | sed -n "$sedcmd" cat "$temp" | ${SED} -n "$sedcmd"
else else
cat "$temp" cat "$temp"
fi fi
@ -251,11 +256,11 @@ for x in ${!site_name[@]}; do
outfile="${OUTDIR}/${thisfile}" outfile="${OUTDIR}/${thisfile}"
temp=$(newtempfile) temp=$(newtempfile)
temp2=$(newtempfile) temp2=$(newtempfile)
curl -sL "$url" | sed 's/>/>\n/g;s/</\n</g;' | awk NF | egrep -v "^<.*>$" > "${temp}" curl -sL "$url" | ${SED} 's/>/>\n/g;s/</\n</g;' | awk NF | egrep -v "^<.*>$" > "${temp}"
sedcmd="/${re_start}/,/${re_end}/p" sedcmd="/${re_start}/,/${re_end}/p"
echo -e "SITE: ${sitename}\nURL: $url\n\n" >${temp2} echo -e "SITE: ${sitename}\nURL: $url\n\n" >${temp2}
cat "$temp" | sed -n "$sedcmd" >> ${temp2} cat "$temp" | ${SED} -n "$sedcmd" >> ${temp2}
if [[ -e ${outfile} ]]; then if [[ -e ${outfile} ]]; then
# has it changed? # has it changed?