Let's suppose I have this variable:
DATE="04\Jun\2014:15:54:26"
Therein I need to replace \
with \/
in order to get the string:
"04\/Jun\/2014:15:54:26"
I tried tr
as follows:
echo "04\Jun\2014:15:54:26" | tr '\' '\\/'
But this results in: "04\Jun\2014:15:54:26"
.
It does not satisfy me. Can anyone help?
Press \/ to change every backslash to a forward slash, in the current line. Press \\ to change every forward slash to a backslash, in the current line.
To replace content in a file, you must search for the particular file string. The 'sed' command is used to replace any string in a file using a bash script. This command can be used in various ways to replace the content of a file in bash. The 'awk' command can also be used to replace the string in a file.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With