Visit Our UNIX and Linux User Community


display content between all similar tags pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting display content between all similar tags pattern
# 1  
Old 10-19-2009
display content between all similar tags pattern

hi, I m stuck at a point for more than 3days. My doubt is pretty simple..
I have a web page content in $content. ( got this by using LWP)..

Now I want to display the content matching a pattern.

I tried
Code:
  if($content =~ m{<div class="abc">(.*?)</div>}s){
   print $1;}

that will display for only 1st pattern match..
Now I want to display content between each <div class="abc"> and </div> occuring in the $content and store in array.

Pls help me out how to do it...
how should i apply the while loop..

thanx..

Last edited by pludi; 10-19-2009 at 04:35 AM.. Reason: code tags, please...
# 2  
Old 10-19-2009
you will also need the multiline modifier.. see perldoc perlre
# 3  
Old 10-19-2009
what is multiline modifier...
I only want to know how could i apply while loop...
around the if condition so that it searches entire $content..

thankx
# 4  
Old 10-19-2009
Hint 1: The modifier 'g' means 'global'
Hint 2:
Code:
$ echo '/a/ /b/ /c/ /d/' | perl -le '$c=<>; @a=($c=~m{/(.*?)/}g); print "@a";'
a b c d

Hint 3: perldoc perlretut, perldoc perlre
# 5  
Old 10-19-2009
I tried
code:
Code:
@arr=($content =~ m{<div class="abs\c">(.*?)</div>}g);
print @arr;

but when i try putting s instead of g it print the content inside first occuring <div> tags pair in $content..

i still could not figure out the problem...

---------- Post updated at 03:02 AM ---------- Previous update was at 03:00 AM ----------

Code:
@arr=($content =~ m{<div class="abs\c">(.*?)</div>}g);
print @arr;

its not working

---------- Post updated at 03:27 AM ---------- Previous update was at 03:02 AM ----------

I got the it..!!!! jsst put s and g together... as...

Code:
@arr=($content =~ m{<div class="abs\c">(.*?)</div>}sg);
print @arr;


Previous Thread | Next Thread
Test Your Knowledge in Computers #376
Difficulty: Medium
HP-UX was UNIX V7 compliant.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetch lines between 1st and 4th similar pattern

Hi Folks, I have a big file that looks like below ========== kjhjl kjlklkkhcgflj fgf ========== xsww23edc ccdde3rfv ceerfcc vff4 ========== zaq12wsx xsw23edc ========== ========== (3 Replies)
Discussion started by: jayadanabalan
3 Replies

2. UNIX for Dummies Questions & Answers

Crunch character combination and discard similar content

Hi guys ! I generated the power set of the set S={a,b,c} using crunch: crunch 1 3 abc and get the 39 possible subsets: a b c aa ab ac ba bb bc ca cb cc … (2 Replies)
Discussion started by: beca123456
2 Replies

3. Shell Programming and Scripting

Join all the lines matching similar pattern

I am trying to Join all the lines matching similar pattern. Example ; I wanted to join all the lines which has sam to a single line. In next line, i wanted to have all the lines with jones to a single line....etc > cat sample.txt sam 2012/11/23 sam 2012/12/5 sam 2012/12/5 jones... (2 Replies)
Discussion started by: evrurs
2 Replies

4. UNIX for Dummies Questions & Answers

Find next line based on pattern, if it is similar pattern skip it

Hi, I am able to get next line if it is matching a particular pattern. But i need a way to skip if next line also matches same pattern.. For example: No Records No Records Records found got it Records found Now i want to find 'Records found' after 'No Records' pattern matches.. ... (5 Replies)
Discussion started by: nagpa531
5 Replies

5. Shell Programming and Scripting

awk to search similar strings and arrange in a specified pattern

Hi, I'm running a DB query which returns names of people and writes it in a text file as shown below: Carey, Jim; Cena, John Cena, John Sen, Tim; Burt, Terrence Lock, Jessey; Carey, Jim Norris, Chuck; Lee, Bruce Rock, Dwayne; Lee, Bruce I want to use awk and get all the names... (9 Replies)
Discussion started by: prashu_g
9 Replies

6. Shell Programming and Scripting

Help with merge two file based on similar column content

Input file 1: A1BG A1BG A1BG A1CF A1CF BCAS BCAS A2LD1 A2M A2M HAT . . Input file 2: A1BG All A1CF TEMP (5 Replies)
Discussion started by: perl_beginner
5 Replies

7. UNIX for Dummies Questions & Answers

merge lines within a file that start with a similar pattern

Hello! i have a text file.. which contains the data as follows i want to merge the declarations lines pertaining to one datatype in to a single line as follows i've searched the forum for help.. but couldn't find much help.. how can i do this?? (1 Reply)
Discussion started by: a_ba
1 Replies

8. Shell Programming and Scripting

Want to grep for a pattern and display the content above that pattern

Hi, When we have a failure, sometimes we just step restart the job from the next step. Later when we open the log for analysis of the failure, it is becoming difficult to go to the failure part. For eg., if it is a 1000 line log, the failure may be at 500th line. so wat i want to do is, grep... (6 Replies)
Discussion started by: ajayakunuri
6 Replies

9. Linux

Command that prints content of line5, or similar?

Hello all; I've been having trouble completing a script (bash) because I can't get past the issue of finding a line in a file. For example, I have a file like this: ddmmmyyyy Lon Lat 24may2003 -100.0 24.1 25may2003 -100.1 24.0 28may2003 -99.5 23.2 ....etc... (4 Replies)
Discussion started by: lunchtime
4 Replies

Featured Tech Videos