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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Translate

Status
Not open for further replies.

BIS

Technical User
Jun 1, 2001
1,893
NL
Hello,

Can I use the tr command to translate the date format?

Suppose I have a file "date". The contents are only this:

09/12/2002

Can I use the tr command to change this to:

12-09-2002

If so, could somebody point me in the right direction? Any help much appreciated. As you can see this is a date, and it will be changing daily. Is there a way to make tr see that this is a date and change the format?

Or should I be using a different tool alltogether?
 
tr is fine for your needs; try :
date|tr "/" "-"

HTH ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Bis:

tr does the separator as dickie has shown, but it looks like you're also needing to swap fields 1 & 2. Either modify the command that creates your date output of do something like this:


echo "09/12/2002"|awk ' BEGIN { FS="/" }
{
print $2"-"$1"-"$3
} '

Regards,

Ed
 
dickiebird's solution is OK, just a typo
(supposed date is a file)
cat date | tr '/' '-'
don't forget in unix you have different way to do the same
sed -e 's/\//-xxx-/g' date
you get
12-xxx-09-xxx-2002


------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
hi,

why don't you just use date to format the date i.e.

date +%d"-"%m"-"%y > filename

thats is day month year format

hth
 
Thank you all, using the date to format is what I will be going.

If I do date +%d"-"%m"-"%y > filename

my file will look like

17-09-02

is there a way to make it a four digit year

17-09-2002 ?

 
Bis,

just upshift the year part.

date +%d"-"%m"-"%Y
 
:) sometimes life is all too easy.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top