Sed matches unwanted extra characters

Cucazer

I want to replace parts of file paths in a configuration file using sed in Cygwin. The file paths are in form of \\\\some\\constant\\path\\2018-03-20_2030.1\\Release\\base\\some_dll.dll (yes, double backslashes in the file) and the beginning part containing date should be replaced.

For matching I've written following regex: \\\\\\\\some\\\\constant\\\\path\\\\[0-9_\.-]* with a character set supposed to match only date, consisting of digits and "-", "_" and "." symbols. This results into following command for replacement: sed 's/\\\\\\\\some\\\\constant\\\\path\\\\[0-9_\.-]*/bla/g' file.txt

The problem is that, after replacement, I get blaRelease\\base\\some_dll.dll instead of bla\\Release\\base\\some_dll.dll as it was successfully replaced using Regexr.

Why does sed behave this way and how can I fix it?

Jon

The problem is that the character class [0-9_\.-] is matching backslashes. If you replace the class with [0-9_.-], it will do what you expect.

Note that in a character class, . isn't special and doesn't need quoting. For example, from my Cygwin command line:

$ echo '\.' | sed 's/[\.]/x/g'
xx
$ echo '\.' | sed 's/[.]/x/g'
\x

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C++ adding extra, unwanted characters to a string

From Dev

How to use Pattern.matches with regex to filter unwanted characters in a string

From Dev

My Python script is adding extra unwanted characters to my string

From Dev

sed error complaining "extra characters after command"

From Dev

sed on mac: 'extra characters after p command'

From Dev

sed extra characters at end of l command

From Dev

BSD sed: extra characters at the end of d command

From Dev

Removing unwanted characters and empty lines with SED, TR or/and awk

From Dev

Removing unwanted characters and empty lines with SED, TR or/and awk

From Dev

(Sed) Search/Replace Involving Negative Number Yields Extra Characters

From Dev

sed: -e expression #1, char 10: extra characters after command

From Dev

Combine two regular expression rule in sed to remove unwanted characters from string

From Dev

A Linq to replace unwanted characters

From Dev

How to remove unwanted characters?

From Dev

Unwanted Characters in CSV

From Dev

Trimming unwanted characters

From Dev

unwanted partial matches with Python replace

From Dev

Unwanted extra dimensions in NumPy array

From Dev

Remove Unwanted/Extra Data in SQLPLUS

From Dev

Extra unwanted selection from QFileDialog

From Dev

Regex matches extra character

From Java

How to fix sed command on MacOS with error extra characters after \ at the end of c command?

From Dev

why "extra characters after command" error shown for the sed command line shown?

From Dev

Sed - How do I remove the extra characters that show up after running the command?

From Java

How to remove unwanted characters in python

From Dev

jQuery adding unwanted characters to string?

From Dev

Unwanted translation of newline characters in PostgreSQL

From Dev

Unwanted spaces around characters in regex

From Dev

Unwanted characters in regular expressions python

Related Related

  1. 1

    C++ adding extra, unwanted characters to a string

  2. 2

    How to use Pattern.matches with regex to filter unwanted characters in a string

  3. 3

    My Python script is adding extra unwanted characters to my string

  4. 4

    sed error complaining "extra characters after command"

  5. 5

    sed on mac: 'extra characters after p command'

  6. 6

    sed extra characters at end of l command

  7. 7

    BSD sed: extra characters at the end of d command

  8. 8

    Removing unwanted characters and empty lines with SED, TR or/and awk

  9. 9

    Removing unwanted characters and empty lines with SED, TR or/and awk

  10. 10

    (Sed) Search/Replace Involving Negative Number Yields Extra Characters

  11. 11

    sed: -e expression #1, char 10: extra characters after command

  12. 12

    Combine two regular expression rule in sed to remove unwanted characters from string

  13. 13

    A Linq to replace unwanted characters

  14. 14

    How to remove unwanted characters?

  15. 15

    Unwanted Characters in CSV

  16. 16

    Trimming unwanted characters

  17. 17

    unwanted partial matches with Python replace

  18. 18

    Unwanted extra dimensions in NumPy array

  19. 19

    Remove Unwanted/Extra Data in SQLPLUS

  20. 20

    Extra unwanted selection from QFileDialog

  21. 21

    Regex matches extra character

  22. 22

    How to fix sed command on MacOS with error extra characters after \ at the end of c command?

  23. 23

    why "extra characters after command" error shown for the sed command line shown?

  24. 24

    Sed - How do I remove the extra characters that show up after running the command?

  25. 25

    How to remove unwanted characters in python

  26. 26

    jQuery adding unwanted characters to string?

  27. 27

    Unwanted translation of newline characters in PostgreSQL

  28. 28

    Unwanted spaces around characters in regex

  29. 29

    Unwanted characters in regular expressions python

HotTag

Archive