Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash xargs关于保留用于批量html到文本转换的文件名_Bash_Find_Html Parsing_Xargs - Fatal编程技术网

Bash xargs关于保留用于批量html到文本转换的文件名

Bash xargs关于保留用于批量html到文本转换的文件名,bash,find,html-parsing,xargs,Bash,Find,Html Parsing,Xargs,我正在使用html2text将一些html文件转换为文本,并希望将文件名charliesheenwinning.html的名称保留为charliesheenwinning.txt,甚至charliesheenwinning.html.txt 当然,最后一部分-o是错误的。如何在html2text的第一个参数之外继续重用文件名?可以使用for in-exec,但如何使用xargs呢 更新 最后做了什么 find path/to/dir -type f -not -regex ".*\(gif\|p

我正在使用html2text将一些html文件转换为文本,并希望将文件名charliesheenwinning.html的名称保留为charliesheenwinning.txt,甚至charliesheenwinning.html.txt

当然,最后一部分-o是错误的。如何在html2text的第一个参数之外继续重用文件名?可以使用for in-exec,但如何使用xargs呢

更新

最后做了什么

find path/to/dir -type f -not -regex ".*\(gif\|png\|jpg\|jpeg\|mov\|pdf\|txt\)$" -print0 | xargs -0 -L10 --max-procs=0 -I {} html2text -o {}.txt {}
mkdir dir/w/textfiles
cp -r path/to/dir dir/w/textfiles
find dir/w/textfiles -type f -not -regex ".*txt$" -print0 | xargs -0 -L10 --max-procs=0 -I {} rm {}
不是最好的。。但不管怎样。。
[万一您想知道为什么find参数中的名称不仅仅是一个简单的名称“*html”,这是一个mediawiki的wget…]

您应该尝试使用basename:

$ man basename

我也面临着同样的问题——为了记录在案,以下是我将Substion转换成xargs的方法:

seq 100 | xargs -I % -n 1 -P 16 bash -c 'echo % `sed "s/1/X/" <<< %`'

除非您告诉xargs sh-c…,否则xargs不会通过shell处理其命令,然后您可能会遇到引用问题。最简单的方法是创建一个小的shell脚本来完成需要做的事情,并从xargs中调用它。@geekosaur。。。是的,我正在尝试这样做,但问题是将文件名从xargs传递到该命令。xargs-0-L10{}max process=0 sh-c html2text'{}>'{}.txt'xargs:{}:没有这样的文件或目录,我怀疑这是因为使用了错误的xargs语法;如前所述,您正在尝试执行名为{}的命令,其参数为`'max-process=0''sh'-c'html2text'{}'>'{}.txt'。你到底想用它来完成什么?只需在'find./-typef-not-regex.*\png\| jpg\| gif\$';执行html2text$i-o`basename$i.html`.txt;完成;但是在.*\png\| jpg\| gif\$和'basename$i.html`.txt.Uh.之间会有一个不好的交互。如果你在浏览维基媒体,请注意他们有一个更好使用的API:@Vamana谢谢你的指针。。。它会允许没有数据库访问权限的非管理员提取文本内容吗?
seq 100 | xargs -I % -n 1 -P 16 bash -c 'echo % `sed "s/1/X/" <<< %`'
10 X0
3 3
12 X2
4 4
11 X1
1 X
15 X5