Reputation: 73
I am trying to grep
lines that contain words consisting in just digits.
So given a sample file like this:
abcd
abcd 123
adef1234
I am looking to output the line abcd 123
and assign it to a variable. I tried the below:
grep -w '^[0-9]$' test_file.txt
But its not working. Can anyone please help me out?
Upvotes: 1
Views: 2420
Reputation: 12908
In grep ^
and $
match start and end of line even if there is -w
flag enabled. And you need to enable extended regexps (-E
flag) to use +
. Try
grep -E -w '[0-9]+' test_file.txt
Upvotes: 3