vijay Daggumati
vijay Daggumati

Reputation: 39

How to Disable special character functionality in shell script?

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

Upvotes: 0

Views: 227

Answers (1)

Fazlin
Fazlin

Reputation: 2337

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

Upvotes: 1

Related Questions