簡體   English   中英

指定要處理為 Perl 單行的文件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM