1

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 *.

2
  • 1
    Maybe grep -o 'USA_word[^[:blank:]]*'? That should work if by "expressions" you mean any 0+ non-whitespace chars. Commented Sep 25, 2017 at 12:29
  • Works like a charm, thanks! Commented Sep 25, 2017 at 12:31

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.