In a .txt there are several DNIs, what I want to do is use the grep filter command to get the DNIs that have 9 numbers and 1 letter. I've tried this command but it doesn't work:
INSIDE THE FILE:
123456789A
31232g
42344324f
324f
4554345345345g
234452l
INSTRUCTION I HAVE USED:
cat nif.txt|grep -E "[[:digit:]]{9}[[:alpha:]]{1}"
123456789A
4554345345345g
I get the wrong ID and that's what I don't want it to do. Thanks in advance
I suppose that if you count from the beginning those 9 characters plus the letter and also specify that later there should not be more characters, you will get it.
To do this, use the symbol
^
that indicates that the match to be searched for should start the line, and at the end you put a symbol$
that indicates that after the pattern to be searched for there should be nothing else (indicates the end of the line):because otherwise, as you had it, it didn't matter if more characters came out before finding it or after (for example, this was also found: 423443246fXXX `.