perl query using -pie

前端 未结 3 523
无人及你
无人及你 2021-01-11 23:47

This works:

perl -pi -e \'s/abc/cba/g\' hellofile

But this does not:

perl -pie \'s/cba/abc/g\' hellofile

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 00:09

    Because -i takes an optional extension for backup files, e.g. -i.bak, and therefore additional flags cannot follow directly after -i.

    From perldoc perlrun

    -i[extension]

    specifies that files processed by the <> construct are to be edited in-place. It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print() statements. The extension, if supplied, is used to modify the name of the old file to make a backup copy, following these rules:

    If no extension is supplied, no backup is made and the current file is overwritten.

    If the extension doesn't contain a * , then it is appended to the end of the current filename as a suffix. If the extension does contain one or more * characters, then each * is replaced with the current filename. In Perl terms, you could think of this as:

提交回复
热议问题