2017-10-13 238 views
0

我有一份工作正在进行,但我无法弄清楚接下来要做什么。我们收到了一个电子邮件列表,我们将重新格式化它。 它在使用过滤器在Linux中删除电子邮件地址的一部分

给出
[email protected] LastName, Firstname 

它必须采用以下格式:

LastName, FirstName [email protected] 

我能够重新安排一切,所以它是正确的格式,但我不能删除的imapNumber部分电子邮件。有人可以帮助我吗?

到目前为止,我已经做了以下内容:

要获得只有我做了以下命令的电子邮件地址:

cut -d" " -f1 addressbook|cat>emails 

要获得姓氏名字,我做了下面的命令:

cut -d, -d" " -f2 addressbook|cat>names 

以下信息源自地址簿

[email protected] Li,Yi-Huey 
[email protected] Solis,Erica 
[email protected] Ismail,Eiko 
[email protected] Rangel,Juvenal 
[email protected] Vo-le,Trang 
[email protected] Wang,Meiping 
[email protected] Xiao,JunHui 
[email protected] Chen,Lihua 
[email protected] Luo,Yan 
[email protected] Raghuram,Edupuganti 
[email protected] Natkin,William 
[email protected] Armstrong,Craig 
[email protected] Ram,PrasadVanam 
[email protected] Kambam,SuneethaR 
[email protected] Crawford,Chris 
[email protected] Robinson,Lisa 
[email protected] Adi,SrikanthReddy 
[email protected] Fletcher,Derrick 
[email protected] Hanchate,Bhavaniprasad 
[email protected] Kambhampati,RamaKrishna 
[email protected] Kanumuri,RangaRaju 
[email protected] Kothamachu,Pradeep 
[email protected] Kurumaddali,Venkata 
[email protected] Liu,Xiaomei 
[email protected] Mahakali,Radha 
[email protected] Murugesan,Monikadevi 
[email protected] Palleti,Venkata 
[email protected] Shanmugam,Viji 
[email protected] Wei,Helen 
[email protected] Xiao,Li 
[email protected] HanumanthaReddy,Madhu 
[email protected] Chakkarabavi,Beena 
[email protected] Kang,Yi 
+0

用'awk'做它,那么你不必将每一列保存到一个文件中。 – Barmar

+0

您可以使用它的sub()函数从email列中删除imap#。 – Barmar

+0

欢迎来到Stack Overflow! SO不是免费的编码服务。你必须尝试自己解决问题。如果无法正常工作,请发布您尝试的内容,我们会帮助您解决问题。 – Barmar

回答

0

使用sed从电子邮件中删除imap#.

cut -d" " -f1 addressbook | sed 's/@imap[0-9]*\./@/' > emails 

也没有必要管cat,只是cutsed输出重定向到文件。

cut -d" " -f2 addressbook > names 

还有的在第二cut使用-d,没有意义的。仅使用最后的-d选项。