perl逐行读取txt并查找某一特定字符

2025-05-07 09:19:34
推荐回答(1个)
回答1:

echo"Walmart chief executive Douglas McMillon defendscompany's decision to invest billions in improving its stores and Internetshopping presence" | perl -nle ' $r =  qr"((?:\b[\w'\'']+\b\s*){1,3})\s*McMillon\s*((?:\b[\w'\'']+\b\s*){1,3})"; /$r/ ;  print "3 word before McMillon : $1" ; print "3 wordafter McMillon : $2" '