linux - 查找并更新文件中的电子邮件

标签 linux shell unix sh ksh

我有输入计划文本文件,我应该从 %first_name%.%last_name%@my.com 更改为 first.lastname_%sequence%@my.com

谁能帮我吗?

input file:
column1,column2,column3,jack.jack@my.com,column5
column1,column2,column3,tom.tom@my.com,column5
column1,column2,column3,mike.mike@my.com,column5
column1,column2,column3,albert.albert@my.com,column5

output file:
column1,column2,column3,first.lastname_1@my.com,column5
column1,column2,column3,first.lastname_2@my.com,column5
column1,column2,column3,first.lastname_3@my.com,column5
column1,column2,column3,first.lastname_4@my.com,column5

最佳答案

您可能正在寻找这样的东西:

count=1
for line in `cat <your_input_file>`; do
    echo $line | sed -r "s/,[A-Za-z0-9._%+-]+@my.com,/,first.lastname_$count@my.com,/"
    count=`expr $count + 1`
done

关于linux - 查找并更新文件中的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31316530/

相关文章:

我可以在 C 中的 2 个子进程之间使用相同的管道吗?

linux - 为什么使用 getrusage() 测量的已用用户时间不接近完全一致?

python - linux 上的两个版本的 python。如何将包安装到特定版本的python?

shell - echo 在 Unix 中如何实际工作

shell - Makefile:将命令行参数传递给 Makefile 内的文件

php - JSON 的正确用法?

unix - 如何删除 top(1) 输出的每一行的第二个单词?

python - 在作业文件中加载 virtualenv 以在 linux 集群上运行

linux - 每天在 bash 中提取文件行

linux - 为什么我必须输入 "\\\0"才能在zsh中创建一个字符串 "\0"?