Results 1 to 10 of 16
hey guys i just started on sed programming,and i need to replace a "/" with a @,but i try to use the normal way i could not do this,i see ...
- 09-25-2007 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 25
Need Sed help!!
hey guys i just started on sed programming,and i need to replace a "/" with a @,but i try to use the normal way i could not do this,i see a example that replacement is like this command
sed "s/Hello/Hi/g" File.txt>File1.txt
so i type like this
sed "s///@/g" File.txt>File1.txt
but it say what sed: garbled command s///@/g
i totally new to sed program,but need to use it for my project,so have to learn it..anyone pls help me thanks!
- 09-25-2007 #2Just Joined!
- Join Date
- Jul 2007
- Posts
- 41
You need to escape the slashes with back-slashes, so everywhere you want a '/', write '\/'.
Code:sed "s/\//@/g" File.txt>File1.txt
- 09-25-2007 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you need to learn about sed, then you should learn awk as well. a more readable version. sub() means substitute.
Code:awk '{sub("/","@");print}' file
- 09-25-2007 #4Just Joined!
- Join Date
- Aug 2007
- Posts
- 37
Use a different delimiter:
Code:sed "s_/_@_g" File.txt >File1.txt
- 09-26-2007 #5Just Joined!
- Join Date
- Sep 2007
- Posts
- 25
New help needed
hey guys,thanks alot!!it work!!haha..there is still alot i dont understand about sed Programming,as i nw taking over other pple work so have to relearn from start,i knw that sed can delete sentences with a single word like
sed "/hello/d" file.txt>file1.txt
but if i wanna delete not only "hello" but also like "hi" in a sentence hw can i do it?thanks for the replies!!and hope new replies come fast..haha..
- 09-26-2007 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 09-26-2007 #7Just Joined!
- Join Date
- Sep 2007
- Posts
- 25
- 09-26-2007 #8Just Joined!
- Join Date
- Jul 2007
- Posts
- 41
Using the or operator '\|' you can do the two in one replacement:
or with multiple replace commandsCode:sed 's/hello\|hi//'
Code:sed 's/hello//; s/hi//;'
- 09-27-2007 #9Just Joined!
- Join Date
- Sep 2007
- Posts
- 25
Hi thanks for the replies!!but sorry here am i with another question,pls help a sed noob
ok heres the problem,i wanna delete a line when the line have like two word in common for example
/hi/hello/how/are/u
for example i wanna the line to be deleted and be replaced by another line when the line meet the character "hi" and "hello",is that possible?hope replies come fast
- 09-27-2007 #10Just Joined!
- Join Date
- Aug 2007
- Posts
- 37
If you want to learn lots of daft sed tricks have a look at this page:Code:w1="hi" w2="hello" r="This is the replacement line." sed -e "s/.*$w1.*$w2.*/$r/" -e "s/.*$w2.*$w1.*/$r/" file.txt
http://www.student.northpark.edu/pem...d/sed1line.txt


Reply With Quote
