0

I am trying to fetch a line with the following information -a string1 -b file1.txt -c string3 using grep.

I tried grep -v grep | grep '[b][:space:] *.txt *[c]' grep -v grep | grep '[b] *.txt *[c]'

string1, string3 and file1 are variables. So I am looking for solutions using wild characters.

But there is nothing returned. Any help will be appreciated.

3
  • Just use: grep -F -- '-a string1 -b file1.txt -c string3' file Commented Nov 12, 2019 at 19:51
  • Sorry, I wasn't clear in the question. string1, string3 and file1 are variables. So I am looking for solutions using wild characters. Commented Nov 12, 2019 at 19:57
  • 3
    You have a couple of misunderstandings of regex syntax: in regex, "*" doesn't mean "any string", it means "zero or more of whatever's right before this". To get "any string", you need "zero or more of any character", which is ".*". Also, to use a named character class, you need square brackets inside a square bracket expression (i.e. two sets of square brackets): "[[:space:]]" Commented Nov 12, 2019 at 23:16

1 Answer 1

2

You may use this grep:

grep -- '-a [^[:blank:]]* -b [^[:blank:]]*.txt -c [^[:blank:]]*' *.txt 
  • [^[:blank:]] matches any non-whitespace character.
  • -- separates options and pattern arguments.
Sign up to request clarification or add additional context in comments.

1 Comment

Yes it did. Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.