Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
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 ...
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25

    Smile 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!

  2. #2
    Just 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

  3. #3
    Linux 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

  4. #4
    Just Joined!
    Join Date
    Aug 2007
    Posts
    37
    Use a different delimiter:
    Code:
     sed "s_/_@_g" File.txt >File1.txt

  5. #5
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25

    Smile 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..

  6. #6
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by cyberray View Post
    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..

    Code:
    awk '/hello/&&/hi/{next}{print}' file

  7. #7
    Just Joined!
    Join Date
    Sep 2007
    Posts
    25
    Quote Originally Posted by ghostdog74 View Post
    Code:
    awk '/hello/&&/hi/{next}{print}' file
    hi,thanks for the reply,but could u suggest doing the same job using sed programming?Thanks

  8. #8
    Just Joined!
    Join Date
    Jul 2007
    Posts
    41
    Using the or operator '\|' you can do the two in one replacement:
    Code:
    sed 's/hello\|hi//'
    or with multiple replace commands
    Code:
    sed 's/hello//; s/hi//;'

  9. #9
    Just 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

  10. #10
    Just Joined!
    Join Date
    Aug 2007
    Posts
    37
    Code:
    w1="hi"
    w2="hello"
    r="This is the replacement line."
    sed -e "s/.*$w1.*$w2.*/$r/" -e "s/.*$w2.*$w1.*/$r/" file.txt
    If you want to learn lots of daft sed tricks have a look at this page:
    http://www.student.northpark.edu/pem...d/sed1line.txt

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...