LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1339|回复: 1

如何遍历子目录并把列出所有的文件名传递给一个sed脚本

[复制链接]
发表于 2006-12-19 16:19:22 | 显示全部楼层 |阅读模式
找到个sed的html2txt的脚本,因为要转换的html文件分散放在嵌套的子目录下面,
想如何能遍历目录的同时把遇到的每个文件转换成txt?


sed脚本的代码

代码:

#!/usr/bin/sed -nf
#
# Usage:  ./html2txt.sed file.html > file.txt
#                  OR
#         cat file.html | ./html2txt.sed > file.txt
#
# Bugs: Anand Avati <avati@hardcodecafe.com>
#


#/<[^>]*$/b SearchTagEnd
#b ParseHTML
#:SearchTagEnd
#N
#/<[^>]*$/b SearchTagEnd


# convert entire file/stdin into single pattern space
:GetLine
/^[ \t\n]*$/d
N
$b ParseHTML
b GetLine


# start parsing tags
arseHTML

# convert whitespace groups into single ' '
s/[ \t\n][ \t\n]*/ /g

# explicit space
s/&nbsp;/ /g

# fancy stuph
s/&copy;/(c)/g
s/&raquo;/>>/g
s/&middot;/*/g

# standard tags
s/< *[pP] *>/\n/g
s/< *\/[pP] *>/\n/g
s/< *[bB][rR] *>/\n/g

# parse table related tags
# <table>   =>  \n
s/< *[tT][aA][bB][lL][eE] *>/\n/g
s/< *[tT][rR] *>//g
s/< *\/[tT][rR] *>/\n/g
s/< *[tT][dD] *>//g
s/< *\/[tT][dD] *>//g

# <input type="radio" ..>    =>   ( )
s/< *[iI][nN][pP][uU][tT] [^>]*[tT][yY][pP][eE] *= *["]*[rR][aA][dD][iI][oO][^>]*>/( )/g

# <img src="/imag.jpg">   =>  [IMG:/imag.jpg]
#s/< *[iI][mM][gG] *[^>]*[sS][rR][cC] *= *["]*\([^" ]*\)["]*[^>]*>/[IMG:\1]\n/g
s/< *[iI][mM][gG] *[^>]*[sS][rR][cC] *= *["]*\([^" ]*\)["]*[^>]*>//g


#  <script> ... </script> => *nothing*
:ScriptTagUp
/< *[sS][cC][rR][iI][pP][tT].*\/ *[sS][cC][rR][iI][pP][tT] *>.*< *[sS][cC][rR][iI][pP][tT].*\/ *[sS][cC][rR][iI][pP][tT] *>/!b ScriptTagClean
s#\(< *[sS][cC][rR][iI][pP][tT].*/ *[sS][cC][rR][iI][pP][tT] *>.*\)\(< *[sS][cC][rR][iI][pP][tT].*/ *[sS][cC][rR][iI][pP][tT] *>\)#\1#g
b ScriptTagUp
:ScriptTagClean
s#< *[sS][cC][rR][iI][pP][tT].*/ *[sS][cC][rR][iI][pP][tT] *>##g

#  <form ..> ... </form>  => *nothing*
#:FormTagUp
#/< *[fF][oO][rR][mM].*\/ *[fF][oO][rR][mM] *>.*< *[fF][oO][rR][mM].*\/ *[fF][oO][rR][mM] *>/!b FormTagClean
#s#\(< *[fF][oO][rR][mM].*/[fF][oO][rR][mM] *>.*\)\(< *[fF][oO][rR][mM].*/[fF][oO][rR][mM] *>\)#\1#g
#b FormTagUp
#:FormTagClean
#s#< *[fF][oO][rR][mM].*/ *[fF][oO][rR][mM] *>##g

# for now
s/<[^>]*>//g

# we do this in the end to avoid adding confusion to the above
# because > and < can be interpreted as tags

# explicit >
s/&gt;/>/g
# explicit <
s/&lt;/</g

oo
p
发表于 2006-12-20 23:12:47 | 显示全部楼层
这个用find解决就行了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表