strange file format processing

hi
i have file (a metadata type file ) in this format

 
record
string("|") isxml ;
string("|") billing_type ;
string("|") billing_type_desc ;
string("|") ods_create_date ;
string("|") ods_update_date ;
string("|") event_key ;
string("|") target_pid ;
string("|") open_date ;
string("|") close_date ;
end

I want the output where the lines with date in it to be changed to
string("|") to date("YYYY-MM-DD")
so output will be

 
record
string("|") isxml ;
string("|") billing_type ;
string("|") billing_type_desc ;
date("YYYY-MM-DD") ods_create_date ;
date("YYYY-MM-DD") ods_update_date ;
string("|") event_key ;
string("|") target_pid ;
date("YYYY-MM-DD") open_date ;
date("YYYY-MM-DD") close_date ;
end
awk ' ($2 ~ ".*date.*") { $1="date(\"YYYY-MM-DD\")" } 1' infile
1 Like

How about this,

 sed 's/\(.*\) \+\(.*date.*\)/date("YYYY-MM-DD") \2/g' inputfile

alternative with sed..

sed '/date/s/|/YYYY-MM-DD/g' inputfile > outfile
1 Like
sed '/date/s/.*|/date("YYYY-MM-DD/' file
1 Like
date=$(date +%Y-%m-%d)

awk ' ($2 ~ /date/) { $1="date(\"" "'$date'" "\")"}1' infile


record
string("|") isxml ;
string("|") billing_type ;
string("|") billing_type_desc ;
date("2010-11-15") ods_create_date ;
date("2010-11-15") ods_update_date ;
string("|") event_key ;
string("|") target_pid ;
date("2010-11-15") open_date ;
date("2010-11-15") close_date ;
end