Change File Header Timestamp

Please I am new to Unix and this simple question I am already answered but struggling to find the answer.

I have a data file which contains header record which conatins date timestamp. I need to find a way of simply updating the date time stamp to current date timestamp.

So if the header record is:

20081206 then I simply want to update it to 20081207 (i.e. today's date).

I would appreciate if someone can either point me to the related link or simply answer the this question by providing simple code. Note I would add this code to an existing shell script.

Thanks.

Hi,

sed "s/200[012345678][01][0-9][0123][0-9]/$(date +%Y%m%d)/" file >> file.new

will match all the days since "20000000" and replace them by the current
date.

HTH Chris

Sorry I forgot to mention the date in the header record is in dd-mmm-yyyy format e.g. 12-Sep-2008 and there are data records which contain date in the format dd-mm-yyyy e.g. 21-07-2005. So I need to change the date in the header record only.

from:
SDM|PRDHIER|12-Sep-2008|12:00||
CDBCIN|1012348318|C5C18GB|CIS|CIN|21-07-2005
CDBCIN|1012348381|Z3WA3GB|CIS|CIN|31-12-2007
CDBCIN|1012348407|CBFTVGB|CIS|CIN|26-02-2007
CDBCIN|1012348416|CZQO4GB|CIS|CIN|30-03-2006

to:
SDM|PRDHIER|07-Dec-2008|12:00||
CDBCIN|1012348318|C5C18GB|CIS|CIN|21-07-2005
CDBCIN|1012348381|Z3WA3GB|CIS|CIN|31-12-2007
CDBCIN|1012348407|CBFTVGB|CIS|CIN|26-02-2007
CDBCIN|1012348416|CZQO4GB|CIS|CIN|30-03-2006

i.e. only the header record and the rest remains the same.

Thanks.

It's all the same. All you need is:

man date

and the snippet i gave you becomes:

sed "s/[0123][0-9]-[A-Z][a-z]\{2\}-200[0-9]/$(date +%d-%b-%Y)/" file 

Thanks for this, it works perfectly...

sed 's/[0-9][0-9]-[a-zA-Z][a-zA-Z][a-zA-Z]-[0-9][0-9][0-9][0-9]/'`date +%d-%b-%Y`'/' file