LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

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

Rep: Reputation: 0
Question 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.
 
Old 01-06-2009, 06:17 AM   #2
indeliblestamp
Member
 
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:
Code:
grep "myFileCode=\"null#9\"" myfile.xml
 
Old 01-06-2009, 06:18 AM   #3
makuyl
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.
Code:
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
kaprasanna
LQ Newbie
 
Registered: Mar 2007
Posts: 14

Original Poster
Rep: Reputation: 0
arungoodboy

Thanks so much. It worked great.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 10:58 PM.

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