Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
replace text in files with console
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
oc666
Guru
Guru


Joined: 15 May 2006
Posts: 330
Location: Israel

PostPosted: Sat Apr 07, 2007 8:58 pm    Post subject: replace text in files with console Reply with quote

Hello
I've 100 php files. I want to replace the html tag with this:
Code:
<html dir="rtl">
Not all the php files have html tag.
How can I do this with console?

Thanks
_________________
embAD-new way to insert ads to your website
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sat Apr 07, 2007 9:10 pm    Post subject: Re: replace text in files with console Reply with quote

something like this should do the trick
Code:
for i in *; do sed -i '/s/\<html\>/\<html  dir=\"rtl\"\>/' $i; done
... (untested, out of head)
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2483
Location: Silver City, NM

PostPosted: Sat Apr 07, 2007 9:16 pm    Post subject: Reply with quote

Here is another untested solution:
Code:
$ perl -ipe 's/<html[^>]*>/<html dir="rtl">/i' *.php
Back to top
View user's profile Send private message
oc666
Guru
Guru


Joined: 15 May 2006
Posts: 330
Location: Israel

PostPosted: Sat Apr 07, 2007 9:27 pm    Post subject: Reply with quote

Both commands don't work.
I get for the first one (translated from hebrew): sed error in program - unknown command (char no. 4 of expr' -e no. 1)
I get for the second: Can't open perl script "s/<html[^>]*>/<html dir="rtl">/i": No such file or directory
_________________
embAD-new way to insert ads to your website
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2483
Location: Silver City, NM

PostPosted: Sat Apr 07, 2007 9:34 pm    Post subject: Reply with quote

Try:
Code:
$ perl -i -p -e 's/<html[^>]*>/<html dir="rtl">/i' *.php
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sat Apr 07, 2007 9:36 pm    Post subject: Reply with quote

Code:
for i in *.php; do sed -i 's/<html>/<html dir=\"rtl\">/' $i; done

_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
oc666
Guru
Guru


Joined: 15 May 2006
Posts: 330
Location: Israel

PostPosted: Sun Apr 08, 2007 9:14 am    Post subject: Reply with quote

Thanks a lot, Both works just fine.
_________________
embAD-new way to insert ads to your website
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum