Sed 查找信用卡号并在设置的位置替换字符

Sed 查找信用卡号并在设置的位置替换字符,sed,replace,position,credit-card,anonymize,Sed,Replace,Position,Credit Card,Anonymize,我有一个包含信用卡号码(16个字符)的文件,我想找到这些号码,并用“X”替换除前6个和后4个号码之外的所有号码 sed -i 's/\([345]\{1\}[0-9]\{3\}\|6011\)\{1\}[ -]\?[0-9]\{4\}[ -]\?[0-9]\{2\}[-]\?[0-9]\{2\}[ -]\?[0-9]\{1,4\}/\XXXXXX/g' foobar.csv 将很容易找到文件中包含的所有信用卡,并将其替换为“XXXX” 但是我想找到信用卡,并用“X”替换字符串中的7-12个字符

我有一个包含信用卡号码(16个字符)的文件,我想找到这些号码,并用“X”替换除前6个和后4个号码之外的所有号码

sed -i 's/\([345]\{1\}[0-9]\{3\}\|6011\)\{1\}[ -]\?[0-9]\{4\}[ -]\?[0-9]\{2\}[-]\?[0-9]\{2\}[ -]\?[0-9]\{1,4\}/\XXXXXX/g' foobar.csv
将很容易找到文件中包含的所有信用卡,并将其替换为“XXXX”

但是我想找到信用卡,并用“X”替换字符串中的7-12个字符,这样文件将包含像123456xxxxx7890这样被屏蔽的信用

示例输入行:

jam peanut boat handbag on the shore in Tuesday 4548640040302006 in the morning jimmy
样本输出行:

jam peanut boat handbag on the shore in Tuesday 454864XXXXXX2006 in the morning jimmy

尝试使用GNU sed匿名化信用卡号码:

sed -i 's/\(\([345]\{1\}[0-9]\{3\}\|6011\)\{1\}[ -]\?[0-9]\{2\}\)[0-9]\{2\}[ -]\?[0-9]\{2\}[-]\?[0-9]\{2\}[ -]\?\([0-9]\{1,4\}\)/\1XXXXXX\3/g' file
输入:

jam peanut boat handbag on the shore in Tuesday 4548640040302006 in the morning jimmy jam peanut boat handbag on the shore in Tuesday 454864XXXXXX2006 in the morning jimmy 星期二早上,吉米把花生船手提包放在岸上,时间是4548640040302006 星期二早上,在海滩上塞满花生船手提包454864xxxxxxx2006 输出到文件:

jam peanut boat handbag on the shore in Tuesday 454864XXXXXX2006 in the morning jimmy jam peanut boat handbag on the shore in Tuesday 454864XXXXXX2006 in the morning jimmy 星期二早上,在海滩上塞满花生船手提包454864xxxxxxx2006 星期二早上,在海滩上塞满花生船手提包454864xxxxxxx2006
请在您的问题中添加样本输入和该样本输入所需的输出。样本输入行:“在星期二早上把花生船手提包放在岸上,吉米”样本输出行:“在星期二早上把花生船手提包放在岸上,吉米”