Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-06-2009, 06:13 AM   #1
LQ Newbie
Registered: Mar 2007
Posts: 14

Rep: Reputation: 0
Question How to grep for a string in a file


I have an xml file which has many lines like this :
I want to list all the lines which has above string.
I tried the following with no result :

grep "MyFileCode="null#9"" myfile.xml
grep "MyFileCode='"'null#9'"' myfile.xml
How do I solve this seemingly easy problem?

Thanks in advance.
Old 01-06-2009, 06:17 AM   #2
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
You'll need to escape the double quotes with a backslash. This should work:
grep "myFileCode=\"null#9\"" myfile.xml
Old 01-06-2009, 06:18 AM   #3
Senior Member
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 53
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.
grep "myFileCode=\"null#9\"" myfile.xml
Edit: ...and I was too slow.

Last edited by makuyl; 01-06-2009 at 06:20 AM.
Old 01-06-2009, 06:29 AM   #4
LQ Newbie
Registered: Mar 2007
Posts: 14

Original Poster
Rep: Reputation: 0

Thanks so much. It worked great.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
grep the exact string only ZAMO Linux - General 11 08-28-2008 05:08 AM
Grep string and redirect the rest to a file twantrd Programming 6 06-02-2006 07:37 PM
Grep String Search, and identify source file. carl0ski Linux - General 4 01-21-2006 08:15 AM
how to grep only one string pr match gummimann Linux - General 3 11-06-2003 09:40 AM
grep - finding string and replacing with new ckibler Linux - Newbie 6 08-01-2003 06:25 PM

All times are GMT -5. The time now is 03:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration