2

I have this line from file.php:

'user' => '',

What would be the appropriate command using grep to query the exact line?

5

Use double quotes to enclose your pattern:

grep "'user' => ''," your_file

I would also make use of some metacharacters to ensure the lookup is robust to the different spacing styles used by people:

grep "'user'\s*=>\s*''\s*," your_file

To add different keywords to your search, you need extended regular expressions. Supply the -E switch to grep:

grep -E "'(user|group|foo)'\s*=>\s*''\s*," your_file

The above will print lines matching 'user' => '', or 'group' => '', or 'foo' => '', (with different spacing variations). Modify as needed.

2
  • Great. How about to search/query another keyword let say 'group' => '';
    – James W.
    Sep 13 '13 at 2:27
  • @JamesW. Answer updated.
    – Joseph R.
    Sep 13 '13 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.