Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string search and replace

Status
Not open for further replies.

volcano

Programmer
Aug 29, 2000
136
0
0
HK
Hi, your help to solve the below problem is appreciated!

There is a sentence (or the whole line sentence) read from a file and stored in a variable by a script. The sentence looks like:

25.05.2007 04:11:01 PM

Now I want to change the sentence to be:

25/05/2007 04:11:01 PM

How can I do such string search and replace in a script?

Thanks.
 
man sed

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi,
Code:
X="25.05.2007 04:11:01 PM"
echo $X |tr '.' '/'
man tr for more info
 
hi aau, thanks for your response!
Having searched for this forum again, i also find the following command also works:

echo "25.05.2007 04:11:01 PM" | sed `'s/\./\//g'`
 
Hi

That works ? [surprise] Maybe if you remove the back ticks ( ` ) :
Code:
echo "25.05.2007 04:11:01 PM" | sed 's/\./\//g'

[gray]# or to avoid escaping the slash ( / )[/gray]

echo "25.05.2007 04:11:01 PM" | sed 's,\.,/,g'

[gray]# or to avoid escaping the period ( . ) too[/gray]

echo "25.05.2007 04:11:01 PM" | sed 'y,.,/,'

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top