LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to grep for a string in a file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-grep-for-a-string-in-a-file-695305/)

kaprasanna 01-06-2009 06:13 AM

How to grep for a string in a file
 
Hello,

I have an xml file which has many lines like this :
Code:

myFileCode="null#9"
myFileTimeCode="null#123"
myFileMachineCode="null#145"

I want to list all the lines which has above string.
I tried the following with no result :

Code:

grep "MyFileCode="null#9"" myfile.xml
grep "MyFileCode='"'null#9'"' myfile.xml

How do I solve this seemingly easy problem?

Thanks in advance.

indeliblestamp 01-06-2009 06:17 AM

You'll need to escape the double quotes with a backslash. This should work:
Code:

grep "myFileCode=\"null#9\"" myfile.xml

makuyl 01-06-2009 06:18 AM

Use a lower case m in the beginning to match the row in your file, and use backslashes to escape the ":s in the row.
Code:

grep "myFileCode=\"null#9\"" myfile.xml
Edit: ...and I was too slow.

kaprasanna 01-06-2009 06:29 AM

arungoodboy

Thanks so much. It worked great.


All times are GMT -5. The time now is 06:30 AM.