0

i want to replace special string using sed but how to disable special characeter functionality.

%D/%M/%Y %H:%I:%S,%F000 want to replace with %d/%m/%y %H:%i:%s,%f000

sed -i '/s\b%D/%M/%Y %H:%I:%S,%F000\b/%d/%m/%y %H:%i:%s,%f000/g' inputfile.txt
Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31

1 Answers1

1

I found 2 issues in your sed command:

  1. You have placed s after delimiter (/). The search command s should be before delimiter.

  2. Your search pattern contains forward slash and you have used the same as your delimiter which will create issues. sed can use variety of delimiters apart from widely used forward slash. Refer - what-delimiters-can-you-use-in-sed

After fixing both, here is the updated sed command (i have used ! as delimiter):

sed -i 's!%D/%M/%Y %H:%I:%S,%F000!%d/%m/%y %H:%i:%s,%f000!g' inputfile.txt
Fazlin
  • 2,285
  • 17
  • 29