logo
  • 教程列表
  • SO官方文檔
  • Perl 單行
    • 從命令列執行一些 Perl 程式碼
    • 在 Windows 單行中使用雙引號字串
    • 列印與圖案匹配的線條(PCRE grep)
    • 用另一個子字串替換子字串(PCRE sed)
    • 僅列印某些欄位
    • 列印第 5 到 10 行
    • 就地編輯檔案
    • 將整個檔案作為字串讀取
    • 將檔案上傳到 mojolicious
  1. StackOverflow 文件
  2. Perl Language 教程
  3. Perl 單行
  4. 就地編輯檔案

就地編輯檔案

Created: November-22, 2018

沒有備份副本( Windows 不支援 )

perl -i -pe's/foo/bar/g' file.txt

用備份副本 file.txt.bak

perl -i.bak -pe's/foo/bar/g' file.txt

使用 backup 子目錄中的備份副本 old_file.txt.orig(如果後者存在):

perl -i'backup/old_*.orig' -pe's/foo/bar/g' file.txt
  • 將整個檔案作為字串讀取
  • 列印第 5 到 10 行

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明