The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep question. saurabhsinha23 UNIX for Dummies Questions & Answers 3 12-10-2007 09:58 PM
grep question tim-bobby UNIX for Dummies Questions & Answers 4 10-05-2007 08:58 AM
Question about GREP Adriel UNIX for Dummies Questions & Answers 16 03-22-2007 04:03 AM
Another grep question kingdbag UNIX for Dummies Questions & Answers 6 10-26-2006 10:56 PM
Grep question eloquent99 UNIX for Dummies Questions & Answers 4 02-20-2003 06:49 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2004
Registered User
 

Join Date: Jul 2003
Posts: 5
grep & sed question

I'm trying to write a bash script to perform a tedious task, but I have no experience and hardly any knowledge so I've been having a rough time with it.
I'm on Mac OS X, and I want a script to do the following:
I have a directory that has about 200 sudirectories. In each of these directories, there are a number of html files that each include a relative link to an image.
What I want to do is create one html file that contains all the img tags of all the html files in all the sudirectories. I would also like to turn all the relative links into absolute ones (meaning: I want each src attribute to contain the full path on my system of the html file -and image, they are in the same directory-).
I've been at it with sed, but one of the problems seems to be that some of the html files don't have regular UNIX line endings, so it's kind of hard for me to extract just those line with img files (I get the full files), let alone img tags.
What I've been toying with is the following (where you'll see that I try to put some line endings back where I think they'd be useful - though for some reason it doesn't work as expected):

#!/bin/bash

for pic in ./advanced/*/image??.html
do
grep img $pic | sed "s/img/img\
/" | cat >> images.html
done

This script doesn't address the absolute link problem yet.

Any help would be greatly appreciated.

Last edited by der Kopf; 11-20-2004 at 01:00 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-22-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Just a couple of ideas....

For the end of line problem, use tr or dos2unix (if applicable and installed) to replace the end of line characters with \n.

For getting the absolute path, have a look at "dirname".

Cheers
ZB
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0