shell修改html电子书标题
# shell 修改html电子书标题 # 使用file命令无法判断得到这个编码,只好用leafpad,得到gb2312 # 转码 cd ebook mkdir utf8 for i in *html;do iconv -f gb2312 -t utf8 $i -o utf8/$i; done mv utf8/* . rmdir utf8 # 获取标题 有25个 grep -P '^第([^0-9]*)章' *html>foo.dat # 替换<title>...</title> # 测试使用,在后面添加grep和显示文件名,以保证结果的正确 # for i in {001..025}; do # j=`sed -n "${i}p" foo.dat`; # sed "s/<title>.*/<title>$j<\/title>/" -i ${i}.html|grep title; # echo $i; # done for i in {001..025}; do j=`sed -n "${i}p" foo.dat`; sed "s/<title>.*/<title>$j<\/title>/" -i ${i}.html; echo $i; done
转码完成后,也可以不使用文件
a=`grep -P '^第([^0-9]*)章' *html` for i in {001..025}; do j=`sed -n "${i}p" <<<"$a"`; sed "s/<title>.*/<title>$j<\/title>/" -i ${i}.html; echo $i; done