正则表达式的搜索和替换,重新格式化的名字 - Regex search and replace - reformatting name

- 此内容更新于:2015-12-20
主题:

我都从三星手机联系人A411在一个大文件,导入到三星GalaxyS3电话/联系人。只有一个字段,我不能做一个标准的“替换”,使用凯特。这就是我需要做的事:N:米老鼠取代..N:鼠标;米奇;;;

原文:

I have all the mobile phone contacts from a Samsung A411 in one large file, to be imported into a Samsung Galaxy S3 phone/contacts.

There is just one field that I can't do a standard 'replace' with, using Kate. Here is what I need to do:

N:Mickey Mouse

to be replaced with ..

N:Mouse;Mickey;;;

解决方案:
使用sed:
原文:

Using sed:

sed -r 's/N:(\w*) (\w*)/N:\2;\1;;;/g' file.txt
楼主:谢谢,,几乎工作。这是发生了什么输入N:米老鼠FN:米老鼠输出N:鼠标;米奇;;;N:鼠标;米奇;;;FN:鼠标;米奇;;;FN:鼠标;米奇;;;

(原文:Thanks, that nearly worked. Here is what happened input N:Mickey Mouse FN:Mickey Mouse output N:Mouse;Mickey;;; N:Mouse;Mickey;;; FN:Mouse;Mickey;;; FN:Mouse;Mickey;;;)

楼主:所以,取代了“N:“记录正确,但它又添加了。“FN:“记录不应该被取代,或添加到。

(原文:So, the "N:" record was replaced correctly, but it was added in again. The "FN:" record should not be replaced at all, or added to.)

楼主:决定使用上面的“战略经济对话”的输出,然后手动编辑该文件。谢谢你的帮助。:)

(原文:Decided to use the output from the "sed" above, and then manually edit the file. Thanks for your help. :))

网友:我固定的命令,以避免。如果这提供了一个解决你的问题,请标明答案接受。

(原文:I fixed the command in order to avoid that. If this provides a solution to your problem, please mark the answer as accepted.)