Veliko
Veliko

Reputation: 817

grep only certain expressions involving quotation marks

I have a txt file from which I want to get only the expressions of the type 'USA_word*' where * is whatever ( I don't want the whole line, only the expressions )

I try the command

grep -oP ''USA_word*''

But I get a list :

USA_word
USA_word
USA_word
.....

without the part signified by the *.

Upvotes: 1

Views: 30

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626758

You may use

grep -o 'USA_word[^[:blank:]]*'

The [^[:blank:]]* part matches 0+ non-whitespace chars.

Besides, this does not use -P PCRE option, and uses a pure BRE POSIX regex making it compatible with the majority of grep implementations.

Upvotes: 1

Related Questions