sed command to delete a string containing / ,\ characters

Mike

I have a String

/abc/gef        \*(cse,fff)

to delete from a file,have to match the full string pattern,tried with

sed -i '//abc/gef        \*(cse,fff)/d' filename

but this ends in an error:

sed: -e expression #1, char xx: expected newer version of sed

I also tried the following options but didn't work:

sed -i '/\/abc\/gef        \*(cse,fff)/d' filename
sed -i 's|/abc/gef        \*(cse,fff)||g' filename

What is the right command for this?

terdon

The problem is that both \ (escape character) and * (0 or more) have a special meaning in regular expressions, so you need to escape them in order to use them as literal characters. Now, the way to escape something is to add a \ before it. So, in order for * to match a literal asterisk and not mean "0 or more", you would write \*. Similarly, to escape the \ you would write \\. Putting this together, we have:

$ cat file 
foo
bar
/abc/gef        \*(cse,fff)
baz

And:

$ sed '/\/abc\/gef        \\\*(cse,fff)/d' file 
foo
bar
baz

Note how I have also escaped the / since // is the match operator in sed. This is why we have /\/abc\/gef and not //abc/gef. The d at the end means "delete any line matching this pattern".

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

sed command to replace a string with special characters with another string with special characters

From Dev

Find files containing a specific string and delete line with this string - SSH, SED

From Dev

Using sed to Replace Portion of String Containing Slashes and Special Characters

From Dev

Using sed to replace a string containing any characters in a specific position

From Dev

Delete an entire string from mySql table containing random characters

From Dev

Substitute a string containing && with sed

From Dev

Special characters to mass replace string using sed command

From Dev

.split() a string containing the characters "++"

From Dev

sed command containing variable not working

From Dev

Delete files containing string

From Dev

Delete files containing string

From Dev

Delete line containing a specific string starting with dollar sign using unix sed

From Dev

sed : delete all lines NOT containing string A or B, starting at 2nd line

From Dev

sed - replacing string with variable containing?

From Dev

SED substitute from variable containing special characters

From Dev

Using sed to replace strings containing special characters

From Dev

replace specific characters containing "\" character with sed

From Dev

Sed command to delete lines - variable

From Dev

How to use sed to delete lines not containing pattern

From Dev

Delete characters in range of string

From Dev

How to delete characters in a string?

From Dev

Batch – Delete Characters in a String

From Dev

Trying to delete string characters

From Dev

How to delete characters in a string?

From Dev

Delete characters in range of string

From Dev

Delete characters in a string Python

From Dev

String to int while containing characters

From Dev

String literal containing control characters

From Dev

Replace a string containing newline characters

Related Related

  1. 1

    sed command to replace a string with special characters with another string with special characters

  2. 2

    Find files containing a specific string and delete line with this string - SSH, SED

  3. 3

    Using sed to Replace Portion of String Containing Slashes and Special Characters

  4. 4

    Using sed to replace a string containing any characters in a specific position

  5. 5

    Delete an entire string from mySql table containing random characters

  6. 6

    Substitute a string containing && with sed

  7. 7

    Special characters to mass replace string using sed command

  8. 8

    .split() a string containing the characters "++"

  9. 9

    sed command containing variable not working

  10. 10

    Delete files containing string

  11. 11

    Delete files containing string

  12. 12

    Delete line containing a specific string starting with dollar sign using unix sed

  13. 13

    sed : delete all lines NOT containing string A or B, starting at 2nd line

  14. 14

    sed - replacing string with variable containing?

  15. 15

    SED substitute from variable containing special characters

  16. 16

    Using sed to replace strings containing special characters

  17. 17

    replace specific characters containing "\" character with sed

  18. 18

    Sed command to delete lines - variable

  19. 19

    How to use sed to delete lines not containing pattern

  20. 20

    Delete characters in range of string

  21. 21

    How to delete characters in a string?

  22. 22

    Batch – Delete Characters in a String

  23. 23

    Trying to delete string characters

  24. 24

    How to delete characters in a string?

  25. 25

    Delete characters in range of string

  26. 26

    Delete characters in a string Python

  27. 27

    String to int while containing characters

  28. 28

    String literal containing control characters

  29. 29

    Replace a string containing newline characters

HotTag

Archive