Issue
how to use grep to get numbers that will not contain 3 and 7, not strings!
I try that
grep -o '[[:digit:]^37]*' test
but its not work
Solution
If you have a GNU grep
, you can use
grep -oP '\b[^\D37]+\b' file
The grep -oP '\b[^[:^digit:]37]+\b'
is a synonymic command.
Details:
\b
- a word boundary (may be replaced with(?<!\d)
if you simply want to make sure there are no other digits immediately on the left)[^
- start of a negated bracket expression that matches chars other than:\D
- any non-digit char37
-3
and7
]+
- end of the bracket expression, repeat one or more times\b
- a word boundary (may be replaced with(?!\d)
if you simply want to make sure there are no other digits immediately on the right).
See the online demo:
s='123 456 857 112 i21.'
grep -oP '\b[^\D37]+\b' <<< "$s"
Output:
456
112
To use the same approach for letters, relace \D
with \P{L}
or [:^digit:]
with [:^alpha:]
.
Answered By - Wiktor Stribiżew