查找信用卡号并替换设定位置的字符
Find credit card numbers and replace characters at set positions
我有一个包含信用卡号(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 个字符,因此该文件将包含像这样屏蔽的信用卡 123456XXXXXX7890。
示例输入行:
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\}\)/XXXXXX/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
输出到文件:
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
我有一个包含信用卡号(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 个字符,因此该文件将包含像这样屏蔽的信用卡 123456XXXXXX7890。
示例输入行:
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\}\)/XXXXXX/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
输出到文件:
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