I am trying to look for lines in a file that have one or more instances of 1234
, but no other numbers (non-digit characters are allowed). Any other number should cause the line not to match.
Valid examples:
1234
1234 xxx
xxx 1234
1234 1234
1234 xxx 1234
Invalid examples:
12341234
12345
1234xxx345
1234 345
1234xxx
xxx1234
1234xxx1234
This is what I have used:
grep -E '^([^0-9]*1234)+[^0-9]*$' file.txt
But this command also outputs 12341234 as valid, how do I prevent that?
12341234
has two instances of1234
and no other numbers — so why is it invalid?12341234
constitutes a number that is different than1234
1234
? Presumably OP considers12341234
as one number (in the first paragraph).