LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 12-21-2008, 10:52 PM   #1
jpgauvin
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

Thanks

Jean-Philippe
 
Old 12-22-2008, 03:57 AM   #2
CroMagnon
Member
 
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
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
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
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian jessie/sid; OpenSuSE; Fedora
Posts: 1,591

Rep: Reputation: 162Reputation: 162
http://www.google.com/search?ie=UTF-...d+replace+java might be more helpful in this application.
 
Old 12-22-2008, 06:54 PM   #5
jpgauvin
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

Jean-Philippe
 
  


Reply


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


All times are GMT -5. The time now is 04:01 PM.

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