I have a task to mask the first 12 digits of each credit card number with an asterisk (*) given an input file and print the masked number to an output file.
Example card numbers:
1111-2222-3333-4444
4444-3333-2222-1111
1234-5678-9101-1171
1234 5678 9101 1121
7347_9834_7598_2834
8973#9858#3475#8734
2356`7843`0527`5340
8734=7583=4895=7007
8763+2430+6257_9406
Everything should be done in a shell script
My solution is:
#!/bin/bash
file='cards.txt'
while read data; do
echo $data | sed -r 's/[[:digit:]]{4}/****/;s/[[:digit:]]{4}/****/;s/[[:digit:]]{4}/****/;s/[^0-9,*]+/ /g'
done < $file > cards-masked.txt
Any better ideas on how to use sed in this task?