perl逐行读取txt并查找某一特定字符 40
例如文件1.text是这样的一段话:WalmartchiefexecutiveDouglasMcMillondefendscompany'sdecisiontoinves...
例如文件1.text是这样的一段话:Walmart chief executive Douglas McMillon defends company's decision to invest billions in improving its stores and Internet shopping presence。希望能够找住decision这个词,以及找到Mcmillan以及附近6个文字,应该怎么样?
展开
展开全部
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" '
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询