Changing the date format in a script

Hi,

I run a script which outputs various records, anyway one of the columns contains the date in the format DDMMYYYY, I would like to make this DDMMYY.

Is there an easy way to do this,

Removed.

I think I need a bit more explaining., I think I have found an easier solution.

Here is a sample record:

C,999999,5612,13122010,C,RANDOMD CHARACTERS,ND
C,999999,17140,13122010,C,MORE RANDOM STUFF,ND

I records lengths change, however the date will always be 4th column. This is extracted from a database and I need to remove the millenia year - I.e So it displays 131210 instead of 13122010...

C,999999,5612,131210,C,RANDOMD CHARACTERS,ND
C,999999,17140,131210,C,MORE RANDOM STUFF,ND

Thanks

sed 's/,\([0-9]{4}\)[0-9]{2}\([0-9]{2}\),/\1\2/g' inputfile

Matching a 8 digits number between two ,(comma) and remembering first 4 + last 2 digits of it to exclude 2 unwanted middle digits.

1 Like

Can you run through the command explaining , I can read most of it and understand it but it doesn't seem to be working...

Edited Post#4

which part makes can make it use only the 4th column, I tested the command and it does work perfectly it just doesnt work on the extract as it isn't using the 4th (or am i missing this..)

I appreciate your help

 
sed 's/^\([^,]*\),\([^,]*\),\([^,]*\),\(....\)\(..\)\(..\)\(.*\)/\1,\2,\3,\4\6\7/g' inputFile
1 Like

Returning an error for me that one - unmatched ) or /) at char 75

Correted, Pls try now.
Also a little simpler way:

sed 's/^\([^,]*,[^,]*,[^,]*,\)\(....\)\(..\)\(..\)\(.*\)/\1\2\4\5/g' inputFile

Yeah thats it - thanks.

alternate sed..

sed 's/,\(....\)..\(..\)/,\1\2/2' inputfile > outfile