我有以下檔案:
/Users/x/-acite _1660475490N.html
/Users/x/-acite _1660464772N.html
/Users/x/-acite _1660464242N.html
/Users/x/-acite _1660463321N.html
/Users/x/-acite _1660421444N.html
/Users/x/-acite _1612414441N.html
/Users/x/fix _1660399672N.html
/Users/x/fix _1660398829N.html
/Users/x/water witching _1660460617N.html
/Users/x/water witching _1660388149N.html
/Users/x/water witching _1632222441N.html
/Users/x/water witching _1660003224N.html
我需要
/Users/x/-acite _1660475490N.html
/Users/x/fix _1660399672N.html
/Users/x/water witching _1660460617N.html
我使用以下 perl 正則運算式:
find . -type f -exec perl -pi -w -e 's/(.*)(\R)(.*)(\R)/$1$2/' \{\} \;
或者
find . -type f -exec perl -pi -w -e 's/(.*?)(\R)(.*?)(\R)/$1$2/g;' \{\} \;
為什么這些不起作用?
uj5u.com熱心網友回復:
此外,您可以在paragraph模式 ( -00) 下閱讀,并匹配并列印每個“段落”的第一行。
C:\Old_Data\perlp>perl -00 -ne "print /(. \n)/" test01.txt
/Users/x/-acite _1660475490N.html
/Users/x/fix _1660399672N.html
/Users/x/water witching _1660460617N.html
請注意,這是在 PC 上運行并在陳述句中使用雙引號 (")。在 *nix 機器上,將使用單引號 (')。
uj5u.com熱心網友回復:
你是
- 不要將整個檔案啜飲成單個字串,并且
- 只替換第一次出現
- 而且您不需要這么多組,您只需要一個,因為您想保留比賽的一部分。
你需要
find . -type f -exec perl -0777 -i -pe 's/^(. )(?:\R. )*\n/$1/gm' \{\} \;
這里,
-0777啜飲檔案^- 一行的開始(由于m標志)(. )- 匹配非空行(?:\R. )*- 零個或多個換行符和非空行序列\n- 匹配換行符
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/506230.html
