I have a large file and want to search only specific string. eg. mobNo='xxx-xxx-xxxx' i have a lot of string in this formate.

i am tring grep "mobNo=\'*\'" . can some one help me. Thanks in advance.

Update #1

I tried grep "mobNo='[^']*'" file and grep -io "mobNo='[^']*'" file also, both are not giving any result.

  • Regarding update #1, both forms of the command work for me using a file I created by cutting and pasting from your question. Can you cut and paste a sample from the test file that you are using and put it in the question? (Do a cut-and-paste, do not retype.) Also, what OS are you using? – John1024 Apr 23 '15 at 19:22

Single quotes do not need to be escaped when they are inside double quotes:

grep "mobNo='[^']*'" file

Also, grep uses regular expressions, not shell patterns (globs). In the shell, * matches zero or more of any character at all. In a regex, however, * matches zero or more of the preceding character. Here we use [^']* which means zero of more of any character that is not a single quote.

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.