bash Problem with "sed" command
Hi there,
i want to search and replace strings with sed and normally its no prob but now i am at a point where i dont know further perhaps u could help me. i want to cat a file and replace certain strings with "html" code but with the special sings in html my bash doesnt take the string as i like. here is the cat'ed file: #-------------cat.file------------------- 70 0 0 0 0 70 70 0 0 0 70 #--------------end--------------------- i tried in this one to replace the 70's with the "<img border="0" src="Warning.gif" width="126" height="26"></p>" html code so i took this command: cat cat.file | sed s/70/"<img border="0" src="Warning.gif" width="126" height="26"></p>"/g but no chance he won't replace..... PLEASE help me :scratch: Blubbfish |
hi,
you need to to escape characters ", >, < and / so your shell will bypass them. Code:
cat cat.file | sed s/70/"<img border=\"0\" src=\"Warning.gif\" width=\"126\" width=\"26\"><\/p>"/g |
how do i escape special characters?
Sorry i just did not realize that u postet the new code there ... damn where is my brain today...need more coffee :jawa: Thanks for your help it works perfectly :D But one question is still there sed s/70/"<img border=\"0\" src=\"Warning.gif\" width=\"126\" width=\"26\"\>\<\/p\>"/g why dont i have to uncomment the first < sign ???? doesnt this one try to pipe the word image into something? (Sorry but i'am a :newbie: ) |
you just need to escape special characters. I've edited the code to be "more correct"
everything between " and " is treated as one string by shell, when you want another " in the string you have to escape it. also you have to escape / in the string because sed thinks it's the end of the search part in s/ |
All times are GMT -5. The time now is 07:41 AM. |