I"m trying to use the grep command to print out all occurrences of integer literals in a foo.txt file, but I can't seem to find a way how.
The only thing I can think of for this is using [0-9] as my pattern, but that prints all lines with occurrences of the number rather than just the literals.
EDIT: Say foo.txt contains:
string string1 = "Hello world";
cout << string1.at(2) << endl;
cout << string1at(3) << endl;
Then the expected output would be:
cout << string1.at(2) << endl;
cout << string1at(3) << endl;
Here's another way using lookaround assertions:
Test string:
Regex:
Matches:
Regex example:
http://regex101.com/r/vP5zD7
Use
grep -o [1-9][0-9]* foo.txt
Some like this:
Or to make sure it contains numbers between parentheses: