Fetch images for html

Find img tags with remote source images in an HTML file and download the images to a local folder. Change the HTML files to use the local files instead.

This was done with the one liner:

grep img rbm.html|tr '"' '\n'|grep http|sort -u|while read f;do l=`basename ${f}`;ff=${l%.???};fe=${l##*\.};echo ${ff} ${fe};if [ -f "rbm_pics/${l}" ];then i=1;while [ -f "rbm_pics/${ff}-${i}.${fe}" ];do i=$((i+1));done;l="${ff}-${i}.${fe}";fi;curl --output rbm_pics/${l} "${f}";sed "sX${f}Xrbm_pics/${l}X" rbm0.html > t.html;mv t.html rbm0.html;done

A better formatted version is as follows:

grep img rbm.html|tr '"' '\n'|grep http|sort -u|while read f;do
	l=`basename ${f}`
	ff=${l%.???}
	fe=${l##*\.}
	echo ${ff} ${fe}
	if [ -f "rbm_pics/${l}" ];then
		i=1
		while [ -f "rbm_pics/${ff}-${i}.${fe}" ];do
			i=$((i+1))
		done
		l="${ff}-${i}.${fe}"
	fi
	curl --output rbm_pics/${l} "${f}"
	sed "sX${f}Xrbm_pics/${l}X" rbm0.html > t.html
	mv t.html rbm0.html
done