I have received an assignment that i'm struggling with where, somewhat simplified, i need to extract 6 arbitrary digits from a dataset that cannot start with 3 binary digits. I am only allowed to use grep-commands. For example, from this dataset:
578696344678
100307548
105768
578696
344678
307548
105768
grep -o '[0-9]\{6\}'
Make it in two steps
grep -Po -e '([01]{3})*(\d{6})' | grep -Po '(\d{6})$'
First getting the matching digits with/without leading 'binary digits'. Second, the 6 digits at the end.
The same thing without extended RegEx
grep -Eo '([01]{3})?([0-9]{6})' | grep -Eo '([0-9]{6})$'
grep -o '\([01][01][01]\)*\([0-9][0-9][0-9][0-9][0-9][0-9]\)' | grep -o '\([0-9][0-9][0-9][0-9][0-9][0-9]\)$'