[英]Specifying file to process to Perl one-liner
我得到了一个 Perl one-liner。 它具有以下形式:
perl -pe'...'
如何指定要处理的文件到程序?
在perlrun手册页中可以找到有关如何启动perl
文档。
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
子句中的{}
应按原样显示。
注意:一些单行使用-n
和显式打印而不是-p
。 以上所有内容也适用于这些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.