I am trying to solve one task given to me by using sed
only. The task is:
Given lines of credit card numbers, mask the first digits of each credit card number with an asterisk (i.e., *) and print the masked card number on a new line. Each credit card number consists of four space-separated groups of four digits. For example, the credit card number 1234 5678 9101 1234 would be masked and printed as **** **** **** 1234.
I have successfully used the following command. It is working as expected and printing the desired output.
sed 's/\([0-9]\{4\}\s\)\{3\}\([0-9]\{4\}\)/**** **** **** \2/'
However, I was trying another solution with \b
and it is not working. I am not able to understand why it is not working. \b
should match the beginning and the space between the words. I know it can be solved with \s
but I want to understand what's wrong with the solution with \b
only.
sed 's/\(\b[0-9]\{4\}\b\)\{3\}\([0-9]\{4\}\)/**** **** **** \2/'
NOTE: Since I have a working solution for it. I just want to understand why my solution using \b
is not working.