sed to add word if pattern exists

Hi,

I have a file with data listed below:

clm_id double,
cnl_id double,
cnl_amt double

I want output to be

clm_id string,
cnl_id string,
cnl_amt double

So replace double by string if the field contains the word _id

I tried

sed -e 's/_id/& string/' filename

The above will not delete double.

I can add one more comand and delete double, but I want to do it in same command if possible

Thanks

Something like this?

$ cat  tmp10
clm_id double,
cln_id double,
cnl_amt double,



$ awk '/_id/{ $2="string,"}1' tmp10
clm_id string,
cln_id string,
cnl_amt double,

Try the following->

sed '/.*_id .*/s/double/string/' FILE
1 Like