Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using gedit text editor with embedded terminal in ubuntu 12.04. I'm trying to search for some text using grep. I want to search for this line of code

'type' => 'select'

I tried:

grep -r '\'type\' => \'select\''

But grep didn't return any results.

So can someone kindly tell me how to search for the code above?

share|improve this question

Surround your search string with double quotes:

grep "'type' => 'select'"
share|improve this answer

You cannot escape single quotes that appear within single quotes. As explained here:

Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

So, you have to use different approaches:

  1. Use double quotes:

    grep  "'type' => 'select'" file 
  2. If you prefer needlessly complex solutions:

    grep  "'"type"'"\ =\>\ "'"select"'" file 
  3. You can always search for any single character instead of specifying the single quotes:

    grep  '.type. => .select.' file 

But just use ", it makes things much more straightforward.

share|improve this answer

cd to the directory that contains your .txt file

cd /path 

Then :

you can use grep "'type' => 'select'" name.txt

or :

`grep "'type' => 'select'" /path/file.txt

Output :

enter image description here

share|improve this answer
The question only concerns the single quotes, not the directory structure or any of grep's other (slightly irrelevant) functionality. – Chris Mar 10 '14 at 6:09
@Chris, indeed, with the -r option (as OP writes), the file name is not necessary. – Brady Trainor Aug 2 '14 at 19:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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