在bash中剪切命令终止于引号

MZi*_*an6 2 unix linux bash shell scripting

所以我试图读取一个文件,其中包含一堆带有电子邮件地址的行,然后是昵称.我试图提取这个昵称,它被括号括起来,如下所示

email@somewhere.com (Tom)
Run Code Online (Sandbox Code Playgroud)

所以我的想法只是用cut来得到这个词Tom,但当我最终得到类似下面的内容时,这就被挫败了

email2@somewhereElse.com ("Bob")
Run Code Online (Sandbox Code Playgroud)

因为Bob有引号,所以cut命令失败如下

cut: <file>: Illegal byte sequence

有谁知道更好的方法吗?还是解决这个问题的方法?

小智 8

重置您localeC(原始未解释的字节序列)以避免Illegal byte sequence错误.

locale charmap
LC_ALL=C cut ... | LC_ALL=C sort ...
Run Code Online (Sandbox Code Playgroud)