nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

perl replace text

This is a discussion on perl replace text within the CentOS / RHEL / Fedora forums, part of the Linux Distribution category; I am trying to remove this line OAS_AD('Top'); from html files find . -type f -name "*.html" | xargs perl ...


Go Back   nixCraft Linux Forum > Linux Distribution > CentOS / RHEL / Fedora

Linux answers from nixCraft.


CentOS / RHEL / Fedora Discussion about Redhat Enterprise Linux or CentOS or Fedora Linux related problems.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-11-2009, 01:08 PM
kasimani's Avatar
Senior Member
User
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Posts: 151
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 4
kasimani is on a distinguished road
Send a message via Yahoo to kasimani
Default perl replace text

I am trying to remove this line OAS_AD('Top'); from html files

find . -type f -name "*.html" | xargs perl -pi~ -e "s/OAS_AD\(\'Top\'\)\;//"

<!--
OAS_AD('Top');
//-->

But no success... pl. help me on this...


Regards
Reply With Quote
  #2 (permalink)  
Old 10-11-2009, 06:12 PM
jaysunn's Avatar
Powered By Linux
User
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: RHEL - OSX
Scripting language: BASH - Learning Ruby
Posts: 602
Thanks: 61
Thanked 80 Times in 72 Posts
Rep Power: 10
jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold
Default

Hey kasimani,

When I first looked at your file, I thought there would be many character escaping. However I was successful with sed and double quotes. SHould work with your perl example.


Code:
shine:~ jasonralph$ cat file.html 
<html>
<body>
<title>JAYSUNNS SUPER HTML PAGE<title/>
asdlasdlaasiodjoiasdjioasjdoasidjioasjd
ajsdopiaiospd
OAS_AD('Top');
qowpdkopqkeopkqpwekopqwe
asdfopksdopfkopaskdfopkasopdfkopaskdfpoksdafk
asdfokaopsdfkopaskdfokaopsdf
asdfokaopsdfkopksadfkpoaksdpfokaspodfkpoaskdfpokasopdf
aosdkfopaskdfpokasofkpoaskfpokpafs
<body/>
<html/>
shine:~ jasonralph$

Code:
shine:~ jasonralph$ cat file.html | sed "s/OAS_AD('Top');//g"
<html>

HTH,

Jaysunn
<body>
<title>JAYSUNNS SUPER HTML PAGE<title/>
asdlasdlaasiodjoiasdjioasjdoasidjioasjd
ajsdopiaiospd

qowpdkopqkeopkqpwekopqwe
asdfopksdopfkopaskdfopkasopdfkopaskdfpoksdafk
asdfokaopsdfkopaskdfokaopsdf
asdfokaopsdfkopksadfkpoaksdpfokaspodfkpoaskdfpokasopdf
aosdkfopaskdfpokasofkpoaskfpokpafs
<body/>
<html/>
shine:~ jasonralph$
__________________
Have a look at what I have been working on
http://www.shellasaurus.com
Reply With Quote
  #3 (permalink)  
Old 10-11-2009, 06:47 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

I've not tested, but I trust jaysunn. One thing it should not be -pi~ -e
Code:
-pie
I'm not sure why you got ~ between i and e.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #4 (permalink)  
Old 10-11-2009, 07:56 PM
jaysunn's Avatar
Powered By Linux
User
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: RHEL - OSX
Scripting language: BASH - Learning Ruby
Posts: 602
Thanks: 61
Thanked 80 Times in 72 Posts
Rep Power: 10
jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold
Default

For Perl Use this:

Code:
for find in $(find . -type f -name "file1.html" ) ; do cat $find | perl -npe "s/OAS_AD\('Top'\);//g"; done

Tested and it seems to work.

Code:
shine:~ jasonralph$ for find in $(find . -type f -name "file1.html" ) ; do cat $find | perl -npe "s/OAS_AD\('Top'\);//g"; done
<html>
<body>
<title>JAYSUNNS SUPER HTML PAGE<title/>
asdlasdlaasiodjoiasdjioasjdoasidjioasjd
ajsdopiaiospd

qowpdkopqkeopkqpwekopqwe
asdfopksdopfkopaskdfopkasopdfkopaskdfpoksdafk
asdfokaopsdfkopaskdfokaopsdf
asdfokaopsdfkopksadfkpoaksdpfokaspodfkpoaskdfpokasopdf
aosdkfopaskdfpokasofkpoaskfpokpafs
<body/>
<html/>
shine:~ jasonralph$

Jaysunn
__________________
Have a look at what I have been working on
http://www.shellasaurus.com
Reply With Quote
Reply

Tags
perl , perl -pie , perl replace text


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
To find and replace in text file nashtech Shell scripting 5 31-01-2010 06:32 AM
How to list and replace file of same name in multiple paths shchandu Shell scripting 1 27-08-2009 07:32 PM
shell script to find and replace a line using a identifier kenray Shell scripting 1 11-05-2009 11:09 PM
Shell Script To change strings / text in a text file jaysunn Shell scripting 1 08-05-2009 05:58 PM
How to replace a command in a file? eawedat Shell scripting 2 20-08-2008 02:07 PM


All times are GMT +5.5. The time now is 10:05 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38