查找和更新文件中的电子邮件

Find and update email in file

我有输入计划文本文件,我应该从 %first_name%.%last_name%@my.com 更改为 first.lastname_%序列%@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