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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace text in multiple files on9west Shell Programming and Scripting 1 05-20-2008 02:35 AM
Find and replace files in multiple folders lodey Shell Programming and Scripting 6 09-28-2007 03:00 AM
How can I replace multiple lines from different files ranga27 Shell Programming and Scripting 2 02-07-2007 08:57 PM
Replace text in match files wilsonchan1000 UNIX for Dummies Questions & Answers 1 12-16-2002 09:21 AM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 03:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-26-2004
Tonka52 Tonka52 is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 14
Replace text in multiple files

Ok guys,

If anyone could help me out on this puppy I'd be very appreciative!

Here's the scenario

I have a string for example :
<img src=BLANK_IMG border=0 width=221 height=12>
or
<img src=IMG border=0 height=12 width=221 >
or anything else really....

need to basically change each one to include alt=""
<img src=IMG alt="" .....yada yada....... >

Every line I need to change is guaranteed to start with "<img" and end with a ">" (of course..) the rest is variable.

Also...for bonus points !!! Those <img tags that DO have the alt="" line already, but in a different position, I want to MOVE IT to be next to the src

eg
move
<img src=IMG border=0 height=12 width=221 alt="">
to
<img src=IMG alt="" border=0 height=12 width=221>


Any ideas?

Thanks!
  #2 (permalink)  
Old 02-26-2004
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
See this posting with the same type of question - should start you off in the right direction.
  #3 (permalink)  
Old 02-26-2004
Tonka52 Tonka52 is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 14
Thanks RTM, I saw that posting but that's just a straightforward find/replace statement - I need something that uses a fair bit of logic!

If a super-human sed statement can do it then great! Otherwise it may be a case of writing a program to read word by word, character by charater until it matches a "<img>" then read ahead until ">" ...manipulate the line, then spit it out... or something like that ???......

Of course....I welcome any other *simpler* ideas!
  #4 (permalink)  
Old 02-26-2004
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Free your mind ....


Search first for "<img src" - check out the grep/egrep/fgrep commands - any line containing that - search for your blank alt="" statement - use a sed command to remove it.

Then run through and insert your new alt="" by searching/replacing border with alt="" border

test it out on a smaller file so you can see if it all works before hitting all your htm/html files.
  #5 (permalink)  
Old 02-26-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
sed 's/ alt=""//;s/\(<img src=[^ ]* \)/\1alt="" /g'
or something like that...
  #6 (permalink)  
Old 02-27-2004
Tonka52 Tonka52 is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 14
Perderabo - that statement is very helpful ! Just need to exclude any line already containing alt"<any text>" ...

Can you help on this?
  #7 (permalink)  
Old 02-27-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
I don't understand the question. Post some sample data that shows what you actually want.

And clarify something: can't one line have two or more occurances of "<img src=....>"?
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 04:11 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