perl -p -i.bak -e 's/search_str/replace_str/g' filename
Run Code Online (Sandbox Code Playgroud)
是什么-p
,-i.bak
s/
以及/g
是什么意思?
cod*_*ict 13
-p
:假设' while (<>) { ... }
'循环程序并打印每个处理过的行.-i.bak
:更改输入文件(filename
)inplace并将文件创建filename.bak
为备份.s in s/
:标记替代g
- 全局替换......第一次更换后不要停止.来自perlrun:
-p
导致Perl假定你的程序周围有以下循环,这使得它迭代文件名参数有点像sed:
Run Code Online (Sandbox Code Playgroud)LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; }