LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-01-2004, 05:11 AM   #1
blubbfish
LQ Newbie
 
Registered: Feb 2004
Posts: 29

Rep: Reputation: 15
Question 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



Blubbfish
 
Old 06-01-2004, 05:54 AM   #2
slano
Member
 
Registered: May 2003
Distribution: slack,gentoo
Posts: 57

Rep: Reputation: 16
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

Last edited by slano; 06-01-2004 at 10:15 AM.
 
Old 06-01-2004, 06:52 AM   #3
blubbfish
LQ Newbie
 
Registered: Feb 2004
Posts: 29

Original Poster
Rep: Reputation: 15
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



Thanks for your help it works perfectly
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 )

Last edited by blubbfish; 06-01-2004 at 07:11 AM.
 
Old 06-01-2004, 10:14 AM   #4
slano
Member
 
Registered: May 2003
Distribution: slack,gentoo
Posts: 57

Rep: Reputation: 16
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/
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM
Bash: "after" or "waitfor" command enemorales Programming 3 06-15-2005 12:04 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM
Newbie problem: Starting YAST gives me "-bash: yast: command not found". cattleya Linux - Software 9 11-20-2003 11:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:29 PM.

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
Open Source Consulting | Domain Registration