Reputation: 13
I want to replace .
with /
in a Unix shell script:
2015.07.25
to 2015/07/25
How can I do this?
Upvotes: 0
Views: 49
Reputation: 3322
No need to get the swiss army knife out to drive a small nail :)
echo "2015.07.25" | tr . /
Translates the character .
to /
.
Upvotes: 1
Reputation: 838
echo "2015.07.25"|sed "s/\./\//g"
Replacing the "." with "/". Used escape character ("\") to escape special meaning of the characters (. and / ).
Upvotes: 2
Reputation: 5890
You can use sed
this says substituted for the characters in the site [.]
(which is just the '.' char) a forward slash. The g
at the end stands for "make this a global substitution, not just replace the first instance.
echo "2015.07.25" | sed 's;[.];/;g'
Result:
$ echo "2015.07.25" | sed 's;[.];/;g'
2015/07/25
Upvotes: 1