The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-11-2007 01:58 AM
grep question tim-bobby UNIX for Dummies Questions & Answers 4 10-05-2007 11:58 AM
Question about GREP Adriel UNIX for Dummies Questions & Answers 16 03-22-2007 08:03 AM
Another grep question kingdbag UNIX for Dummies Questions & Answers 6 10-27-2006 01:56 AM
Grep question eloquent99 UNIX for Dummies Questions & Answers 4 02-20-2003 10:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2004
der Kopf der Kopf is offline
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 05:00 AM..
  #2 (permalink)  
Old 11-22-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0