今天在Perl匹配替換的時(shí)候,發(fā)現(xiàn)有字串只能根據(jù)上一行定位,所以導(dǎo)致我要把2行都匹配出來,后做替換動(dòng)作
開始這樣寫的:
perl -pi -e 's/something/repalceString/g' /Users/Swift/Desktop/config.plist
經(jīng)過Google搜索在http://ask.xmodulo.com/search-and-replace-multi-line-string.html發(fā)現(xiàn)多一個(gè)-0的參數(shù)。
The "-i" option tells Perl to perform in-place editing, meaning that Perl reads the input file, makes substitutions, and writes the results back to the same input file. If you want to dry-run the changes, you can omit this option, in which case the results will be shown tostdoutwithout modifying the input file.
The "-0" option turns Perl into "file slurp" mode, where Perl reads the entire input file in one shot (intead of line by line). This enables multi-line search and replace.
The "-pe" option allows you to run Perl code (pattern matching and replacement in this case) and display output from the command line.
看man perl解釋:
[-0[octal/hexadecimal] ]
加上-0:
perl -0pi -e 's/(?<=something).*?(?=\/\>\s)/repalceString/g' /Users/file.plist