I was thinking to do a search on the second field and if it contains string then add "trim( at the beginning of the first filed and ")" at the end before as. Not sure how I can do it though I know we can use sed for that.
It's working for that. but when i change the i/p to below its bnot working
Tpc.CALCULATED_AMT as CALCULATED_AMT ,date
Tpc.SERVICE_ID as SERVICE_ID ,string
TRC.ITEM_NO as ITEM_NO ,date
TPC.LAST_UPD_TIMESTAMP as LAST_UPD_TIMESTAMP ,string
Are you saying that commas are disappearing from the output? If not, what, exactly, is not working?
Did you notice that the commas are connected to the last field in your data sample in post #7 but they were connected to the next to the last field in your data sample in post #1? Did you notice that there is no comma on the last line of your sample input in post #1, but there is a comma on the last line of your sample input in post #7?
What output are you hoping to get from the sample data provided in post #7?
PS Please use CODE tags (not QUOTE tags) when displaying sample input, output, and code segments.
awk '$NF ~ "string" {$1 = "trim(" $1 ")"} {$NF = ","} 1' file
Tpc.CALCULATED_AMT as CALCULATED_AMT ,
trim(Tpc.SERVICE_ID) as SERVICE_ID ,
TRC.ITEM_NO as ITEM_NO ,
trim(TPC.LAST_UPD_TIMESTAMP) as LAST_UPD_TIMESTAMP ,
If that does not satisfy you need, please carefully create a reasonable, consistent specification including input and output samples and the logics connecting the two.