-1

How to search a pattern and remove the line using sed which contains special characters like "ranasnfs2:/SA_kits/prod"

I tried using a variable to hold the complete string and then recall the variable in sed command but it is not working.

echo $a
ranasnfs2:/SA_kits/prod
    sed -i '/"$a"/d' test.txt
    cat test.txt | grep -i SA
/SA_kits        -rw,suid,soft,retry=4   ranasnfs2:/SA_kits/prod
Frits
  • 7,341
  • 10
  • 42
  • 60
  • Which sed are you using? GNU? Can you identify a character which is guaranteed not to occur in the string to search for? E.g. "%". – Yunnosch Jun 21 '17 at 19:33
  • 1
    Possible duplicate of [Escape a string for a sed replace pattern](https://stackoverflow.com/questions/407523/escape-a-string-for-a-sed-replace-pattern) – Thor Jun 21 '17 at 20:03
  • Switch from `s///` to `s|||`, e.g. – Cyrus Jun 21 '17 at 20:18

1 Answers1

0

You need to escape the slash character. Use this for deleting lines which contain a /:

sed '/\//d' file

John Goofy
  • 1,330
  • 1
  • 10
  • 20