replacing ' ' and :'s with _'s in a variable

Hi guys

In my shell script I have a variable that contains a string that contains the current time.

I want to replace the spaces and colons in the value with underscores.

TIME=`date`
echo $TIME

gives me: Thu Sep 24 16:40:53 BST 2009
I want it to show: Thu_Sep_24_16_40_53_BST_2009

I am okay running 2 lines of script one to remove spaces and one to remove :'s .

many thanks
ali

sed -e 's/ /_/g' -e 's/:/_/g'

works only if you stay in BST for GMT-7 for instance you may want to add another -e 's/-/_/g'

http://www.grymoire.com/Unix/Sed.html#uh-13

can some one suggest some thing generic please that would work on all general strings that have a space and a colon in them rather than a string just containing time in a specific format.

thanks

Be more specific, give an example,
the sed -e will work with everything have you tried it ?

sorry mate. Got it. I didnt fully understand your original example.

thanks a lot :slight_smile: