Replace slash in Bash Replace slash in Bash linux linux

Replace slash in Bash


No need to use an echo + a pipe + sed.

A simple substitution variable is enough and faster:

echo ${DATE//\//\\/}#> 04\/Jun\/2014:15:54:26


Use sed for substitutions:

sed 's#/#\\/#g' < filename.txt > newfilename.txt

You usually use "/" instead of the "#", but as long as it is there, it doesn't matter.

I am writing this on a windows PC so I hope it is right, you may have to escape the slashes with another slash.

sed explained, the -e lets you edit the file in place. You can use -i to create a backup automatically.

sed -e s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g index.html


here you go:

kent$  echo "04/Jun/2014:15:54:26"|sed 's#/#\\/#g'  04\/Jun\/2014:15:54:26

your tr line was not correct, you may mis-understand what tr does, tr 'abc' 'xyz' will change a->x, b->y, c->z,not changing whole abc->xyz..