Srinu Yerusu
Srinu Yerusu

Reputation: 13

Replacing . with / in a Unix shell script

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

Answers (3)

moshbear
moshbear

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

sras
sras

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

Victory
Victory

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

Related Questions