LinuxQuestions.org
Register a domain and help support LQ
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 07-21-2014, 02:49 PM   #1
rJbueno
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
literals string and regex search w/grep


Hello,

I am trying to put together a GREP search for the following:

'<iframe' + *any characters* + '<body'

So basically, searching a DEV codebase for files that have open <iframe> tag followed by any characters followed by an open <body> tag. Is there a way to mix literal strings and "wildcard" type expression?


Thanks
 
Old 07-21-2014, 03:26 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Yes, maybe by means of something like this:
Code:
grep -E '<iframe>.+<body>' file
where the .+ regexp means one or more occurrences of any single character. The problem is if it matches similar strings that you want to be ignored instead, so that you have to further refine your expression.
Moreover, take in mind that there are some applications specific for parsing HTML code. They manage tags in an easy and more robust way than a simple regular expression. Two examples are the HTML::Parser library in Perl or the HTMLParser module in Python, if you're experienced with these scripting languages.

Last edited by colucix; 07-21-2014 at 03:30 PM. Reason: code re-checked
 
Old 07-23-2014, 02:51 PM   #3
bulrush15
LQ Newbie
 
Registered: Jul 2014
Location: West Michigan
Posts: 29

Rep: Reputation: Disabled
I think OP actually wants:

Code:
grep -E '<iframe.+<body>' file
 
  


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
linux grep or awk command - how to search for string + execute couta Linux - Newbie 10 09-03-2011 02:58 AM
How do I use wget and grep to download and scan web pages for a search string? diondeville Programming 14 05-27-2010 01:02 PM
Grep String Search, and identify source file. carl0ski Linux - General 4 01-21-2006 09:15 AM
concentration of string literals with _FUNCTION_ is depreciated dzt Linux - Software 4 10-16-2003 01:38 PM
concentration of string literals with _FUNCTION_ is depreciated dzt Linux - General 0 10-16-2003 04:41 AM


All times are GMT -5. The time now is 01:41 AM.

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