0

I want to replace . with / in a Unix shell script:

2015.07.25 to 2015/07/25

How can I do this?

1
  • 1
    we need more context. Do you mean inside of a text file (or other kind of file, then specify) OR do you mean in the output of a string echo "2015.07.25". OR once your value is assigned to a variable, i.e. myDate="2015.07.25". Please take 15 mins to read what you can when searching for [unix] date reformat, sorted by highest votes, and then update your question to make something answerable. Good luck. Commented Jul 25, 2015 at 20:04

3 Answers 3

2
echo "2015.07.25"|sed "s/\./\//g"

Replacing the "." with "/". Used escape character ("\") to escape special meaning of the characters (. and / ).

Sign up to request clarification or add additional context in comments.

Comments

1

No need to get the swiss army knife out to drive a small nail :)

echo "2015.07.25" | tr . /

Translates the character . to / .

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.