【发布时间】:2014-05-04 08:25:37
【问题描述】:
您好,在以下 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.
【问题讨论】:
-
您不想匹配一组字符或特定单词?
-
您使用
[^abcxyz]匹配不在xyzabc中的字符。 -
你能发布
list.txt的简短例子吗? -
具体用词,我已经更正了问题。
-
list.txt
Activision Deutschland GmbH, Activision Publishing, Inc., ak tronic Software & Services的简短示例它应该在逗号上打断公司名称,但您会看到,当有逗号时,有些不需要打断,因为公司名称的一部分仍在继续。