LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
  Search this Thread
Old 05-28-2010, 04:23 AM   #1
hyowza
LQ Newbie
 
Registered: May 2010
Posts: 1

Rep: Reputation: 0
Simple grep question


I have the following .xml file:

<custID>48</custID>
<suburb>not available</suburb>


There is a bunch of log files on the server where the above line is repeated in mulitple files. I want to match all the files that contain exactly:

<custID>48</custID> AND (note: line break)
<suburb>

I have tried the following:

grep '<custID>48</custID>'.*'<suburb>' *

and no results are displayed. I then changed the text file to remove the line break i.e.:
<custID>48</custID>
<suburb>not available</suburb>

and it works.

I read the man page and various pages where it indicates to use the dollar symbol i.e. "$" to reference a line break, which wasn't worked either (no result outputted):

grep '<custID>48</custID>$'.*'<suburb>' *

Yet the following works just fine:

grep '<custID>48</custID>$' *
 
Old 05-28-2010, 04:34 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
grep '<custID>48</custID>$<suburb>' *


heh heh heh

grep -A 1 '<custID>48</custID>$' * | grep -B 1 '<suburb>'

if the <custID> entry is always followed by a <suburb> entry, then you need only

grep -A 1 '<custID>48' *

since this will display the following line too.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with simple grep command jacksmash Linux - General 3 09-10-2008 06:01 PM
simple read $a / grep question sycamorex Programming 2 01-08-2008 01:07 PM
Simple Text Reformat (sed and grep) mikefazz Programming 2 08-31-2004 08:38 PM
Simple grep command problem acis Linux - General 2 07-16-2004 01:21 PM
Simple grep question - I hope ! MiguelE Linux - Newbie 3 04-16-2004 09:46 AM


All times are GMT -5. The time now is 12:58 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration