正则表达式 – 如何使用sed搜索和替换,而不包括一组字符?
发布时间:2020-12-14 05:37:17 所属栏目:百科 来源:网络整理
导读:您好在以下sed命令中我需要在第二组括号中不接受以下单词组:Inc The Ltd LLC 它会破坏list.txt中的以下数据,使每个公司名称都在一行上,公司名称在逗号后面,但有时“Inc”,“Ltd”,“LLC”和“The”跟随公司. 这是非常先进的正则表达式,我似乎无法得到. sed
您好在以下sed命令中我需要在第二组括号中不接受以下单词组:Inc The Ltd LLC
它会破坏list.txt中的以下数据,使每个公司名称都在一行上,公司名称在逗号后面,但有时“Inc”,“Ltd”,“LLC”和“The”跟随公司. 这是非常先进的正则表达式,我似乎无法得到. sed -re 's/([a-zA-Z.]),(Need code here)/1n2/g' list.txt list.txt包含以下数据: Electronic Arts,Inc.,Electronic Arts Ltd. Activision Publishing,ak tronic Software & Services GmbH Coplin Software Electronic Arts,Inc. Electronic Arts,Inc. In-Fusio Activision Publishing,Inc. Domark Ltd. Electronic Arts,Inc. Aspyr Media,Electronic Arts,Inc. Activision Deutschland GmbH,Activision Publishing,ak tronic Software & Services GmbH,Noviy Disk,Square Enix Co.,Ltd. Electronic Arts,Electronic Arts Ltd. Electronic Arts,Electronic Arts Square,K.K.,MGM Interactive Electronic Arts Ltd. 预期输出(注意逗号): GarageGames,Inc. The Avalon Hill Game Company Microforum International,The Telenet Japan Co.,Ltd. Glu Mobile,Inc. Warner Bros. Digital Distribution Atari,Inc. 解决方法perl -pe 's/([^,]),(?!Inc|LLC|The|Ltd)/1n/g' list.txt (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |