Thanks for your response. However I am not looking this one. I exactly want to know how to use date command in substitution replace string. a log file will be read from the pipeline where each line will have a date string which has to be replaced with the date in different format(Numerical).
I don't think sed will work in this situation. Something like this is more along the lines of what you'll need. It assumes the date you want to transform is the first 5 tokens on each record. It can easily be adapted to convert the date from anyplace in the string, but as most log files contain the date up front, I assumed it was first.
awk '
function execute( cmd, r ) # execute command, return last line of output from command.
{
while( (cmd | getline) )
r = $0;
close( cmd ); # very important to close the pipe
return r;
}
{
$5 = $5 "~"; # assume fields 1-5 are the date
split( $0, a, "~" );
new_date = execute( sprintf( "date -d \"%s\" \"+%%Y%%m%%d%%H%%M%%S\"", a[1] ) );
print new_date a[2];
}
' log-file-name
Thanks for your response. Your suggestion partially satisfies my requirement. However Here abc will be replaced by the current date always. I want to pass "abc" as the input to the data command in the replacement string so that the date will be displayed with respect to "abc" (abc has to be replace by the log date)