微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

正则表达式 – 如何使用sed搜索和替换,而不包括一组字符?

您好在以下sed命令中我需要在第二组括号中不接受以下单词组:Inc The Ltd LLC

它会破坏list.txt中的以下数据,使每个公司名称都在一行上,公司名称在逗号后面,但有时“Inc”,“Ltd”,“LLC”和“The”跟随公司.

这是非常先进的正则表达式,我似乎无法得到.

sed -re 's/([a-zA-Z.]), (Need code here)/\1\n\2/g' list.txt

list.txt包含以下数据:

Electronic Arts, Inc., Electronic Arts Ltd.
Activision Publishing, Inc., ak tronic Software & Services GmbH
coplin Software
Electronic Arts, Inc.
Electronic Arts, Inc.
In-Fusio
Activision Publishing, Inc.
Domark Ltd.
Electronic Arts, Inc.
Electronic Arts, Inc.
Aspyr Media, Inc., Electronic Arts, Inc.
Activision Deutschland GmbH, Activision Publishing, Inc., ak tronic Software & Services GmbH, Noviy disk, Square Enix Co., Ltd.
Electronic Arts, Inc.
Electronic Arts, Inc., Electronic Arts Ltd.
Electronic Arts, Inc.
Electronic Arts, Inc.
Electronic Arts, Inc., 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)/\1\n/g' list.txt

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐