Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-21-2008, 10:52 PM   #1
LQ Newbie
Registered: Nov 2008
Location: Montreal
Distribution: RHEL 4, Fedora, CentOS, Ubuntu
Posts: 8

Rep: Reputation: 0
Question sed with html document

I'm trying to replace the alt="" attribute with alt"image alt text" within all html document found in the folder tree

I've try :

find /home/ -name -f 'image.html' - print | xargs sed -e 's/alt=""/alt="alt text with space"/g'

and nothing append

if I try :

find /home/ -name -f 'image.html' - print | xargs sed -e 's/alt=""/p'

I get all the line found with the argument alt=""

Can someone help me


Old 12-22-2008, 03:57 AM   #2
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
sed does not operate "in place" - running sed on a file produces the new text on the standard output, and leaves the original file unchanged. You should try first copying the file to a backup file name, and running that file through sed to replace the original. e.g:

sed -e 's/alt=""/alt="silly text"/g' original.html.bak > original.html
Old 12-22-2008, 04:06 AM   #3
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Or use the -i option of the GNU sed to edit the file in place. Test it on dummy files before actually put the command in production or make a backup copy of the original files. You never know...
Old 12-22-2008, 04:25 AM   #4
Senior Member
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 3,025

Rep: Reputation: 538Reputation: 538Reputation: 538Reputation: 538Reputation: 538Reputation: 538 might be more helpful in this application.
Old 12-22-2008, 06:54 PM   #5
LQ Newbie
Registered: Nov 2008
Location: Montreal
Distribution: RHEL 4, Fedora, CentOS, Ubuntu
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you all for your answer to my problem

@ AwesomeMachine I'm still not confortable with java yet to try it on a production system

@ colucix I have to change over a 100 files

@ CroMagnon Thanks for the script, I understand better sed now, since it was for several files at once, I did some more recherche and found a good one made by jamiew similar to your script



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
html; character encoding per document tag, not whole document TheLinuxDuck Programming 0 08-14-2008 11:12 AM
how to create an html object from an XML document mohtasham1983 Programming 2 12-20-2007 02:58 AM
Saving part of a html document bruno buys Programming 2 07-17-2007 11:15 AM
simple q: can you use php inside an html document? BrianK Programming 2 12-10-2004 09:31 PM
Fooling a HTML document? eantoranz Programming 11 11-11-2004 07:42 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration