In this HackerRank Grep – B problem solution we have given an input file, with N credit card numbers, each in a new line, your task is to grep out and output only those credit card numbers which have two or more consecutive occurrences of the same digit (which may be separated by a space, if they are in different segments). Assume that the credit card numbers will have 4 space-separated segments with 4 digits each.
If the credit card number is 1434 5678 9101 1234, there are two consecutive instances of 1 (though) as highlighted in box brackets: 1434 5678 910[1] [1]234
Here are some credit card numbers where consecutively repeated digits have been highlighted in box brackets. The last case does not have any repeated digits: 1234 5678 910[1] [1]234
2[9][9][9] 5178 9101 [2][2]34
[9][9][9][9] 5628 920[1] [1]232
8482 3678 9102 1232
Input Format
N credit card numbers. Assume that the credit card numbers will have 4 space-separated segments with 4 digits each.
Constraints
1<=N<=20
However, the value of N does not matter while writing your command.
Output Format
Display the required lines after filtering with grep, without any changes to their relative ordering in the input file.
Problem solution.
grep "([0-9]) *1"
Second solution.
#grep -E '([[:digit:]])1' grep -E -e '([[:digit:]])[[:space:]]1' -e '([[:digit:]])1'
Third solution.
grep -E -e "0(s)?0|1(s)?1|2(s)?2|3(s)?3|4(s)?4|5(s)?5|6(s)?6|7(s)?7|8(s)?8|9(s)?9"
Fourth solution.
grep '00|11|22|33|44|55|66|77|88|99|0 0|1 1|2 2|3 3|4 4|5 5|6 6|7 7|8 8|9 9'