我得到了一个Perl一行程序。它的形式如下:
perl -pe'...'
如何为程序指定要处理的文件?
发布于 2017-01-19 05:23:49
关于如何启动perl
的文档可以在perlrun手册页面中找到。
perl -pe'...' -i~ file [file [...]] # Modifies named file(s) in place with backup.
perl -pe'...' -i file [file [...]] # Modifies named file(s) in place without backup.
perl -pe'...' file.in >file.out # Reads from named file(s), outputs to STDOUT.
perl -pe'...' <file.in >file.out # Reads from STDIN, outputs to STDOUT.
如果文件的名称可以以-
开头,则可以使用--
。
perl -pe'...' [-i[~]] -- "$file" [...]
如果您想修改多个文件,您可以使用以下任何一个文件:
find ... -exec perl -pe'...' -i~ {} + # GNU find required
find ... | xargs -r perl -pe'...' -i~ # Doesn't support newlines in names
find ... -print0 | xargs -r0 perl -pe'...' -i~
在上述所有内容中,方括号([]
)表示可选内容。它们不应出现在实际命令中。另一方面,{}
子句中的-exec
应该显示为-is。
注意:一些一行程序使用-n
和显式打印,而不是-p
。所有这些都同样适用于这些方面。
https://stackoverflow.com/questions/41742890
复制