LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Sed question

[ILUG] Sed question

Tim timod at esatclear.ie
Fri Feb 22 16:50:34 GMT 2002


Ar an 22/2/02 10:54 am, scriobh Rory Winston:

> Hi,
> 
> I'm trying to use sed to do the following: search through a .jsp file for
> any <img> references, and then generate a bare list of the image filenames.
> So a .jsp page with 3 images inline would generate an output of:
> 
> a.gif
> b.gif
> c.gif
> 
> I'm trying to do it like the following (for this example, I'm ignoring any
> complications due to case and/or whitespace):
> 
> sed -n "/img src=\"/,/\">/p" foo.jsp
> 
> But this doesnt just print out image filenames - it prints out entire lines.
> Has anyone done anything like this already? If anyone has any grep-based
> solutions that would be great too. Correct me if I'm wrong, but is sed (and
> Perl) able to handle certain types of multi-line matching that grep cannot?
> 
> Cheers!
> Rory
> 


Here's a grep solution. (kinda)

Not as foolproof as the other ones, and will not work if there are more than
1 img tags on the line.

cat foo.jsp | grep -i img | cut -f2 -d= | cut -f2 -d"\"" | cut -f1 -d"\""

not great, but you can see where I'm coming from.  Of course you could also
recursively cut from s -> r -> c -> = to exclude other attributes, cause
there would probably be other = on the line.  Lot's of other holes in it too
:)

Of course this means that the filename will have to be wrappped in "", which
unfortunately is not always the case :(

I like cut.  Its nice for quick stuff.  it would be great if you could have
multiple character delimeters...

But really in this case, you are much better off with sed! Like the others
have proved!

Tim




-- 
Do something about shoddy internet access in Ireland.
Visit http://www.irelandoffline.com





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell