gpt4 book ai didi

linux - 提取域然后使用 sed/awk/grep/perl 粘贴到同一行

转载 作者:太空狗 更新时间:2023-10-29 11:06:58 26 4
gpt4 key购买 nike

不久前我开始了我的技术冒险 - 正如您从问题中感受到的那样 - 但现在我被困住了,因为在几乎一整天的思考和搜索之后我不知道我的问题的正确解决方案。

简而言之,我得到了一个包含电子邮件和名字的数千行文件。问题是我真的需要另一列仅包含域名本身,例如在电子邮件地址旁边。请看下面的例子。

现在是这样的:

    something@nothing.tld|:|george|-|    anything@another.tld|:|thomas|-|    third@address.tld|:|kelly|-|

我想要的样子:

    something@nothing.tld|:|nothing.tld|--|george|-|    anything@another.tld|:|another.tld|--|thomas|-|    third@address.tld|:|address.tld|--|kelly|-|

我最好的猜测是使用 sed 启动进程并提取域,但我如何才能将提取的域粘贴到我卡住的同一行中。

    sed -e 's/.*@\(.*\)|:|*/\1/'

如果您还可以给出一个简短的解释以及一个真正有帮助的解决方案。

感谢任何帮助。

最佳答案

如果在名为 file1 的文件中有以下数据,

 something@nothing.tld|:|george|-|
anything@another.tld|:|thomas|-|
third@address.tld|:|kelly|-|

可以使用:@作为分隔符,使用awk在其后添加数据,然后保存到新文件中,

awk -F '[@:]' '{ print $1"@"$2 ":|" $2"--" $3 }' file1 > file2

以上命令将以下数据保存在名为 file2 的文件中,

something@nothing.tld|:|nothing.tld|--|george|-|
anything@another.tld|:|another.tld|--|thomas|-|
third@address.tld|:|address.tld|--|kelly|-|

关于linux - 提取域然后使用 sed/awk/grep/perl 粘贴到同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50093390/

26 4 0
文章推荐: linux - 风流与netcoreapp2.0
文章推荐: ios - 在单元格中编辑 UITextView 时,iOS 7 中的 UITableView 不会滚动到正确的位置
文章推荐: css -