Well, I have a file test.txt
#test.txt odsdsdoddf112 test1_for_grep dad23392eeedJ test2 for grep Hello World test garbage
I want to extract strings which h
If you're sure you have no leading whitespace, add a ^
to match only at the start of a line, and change the *
to a +
to match only when you have one or more alphanumeric characters. (That means adding -E
to use extended regular expressions).
grep -Eo "^[[:alnum:]]+[[:blank:]]" test.txt
(I also removed the .
from the middle; I'm not sure what that was doing there?)