Reputation: 705
I am trying append and prepend some text to each word using sed
My input is:
abc, def
I am expecting the output to be:
cast(abc as string), cast(def as string)
I am trying to do something similar to this:
test='abc, def'
echo "${test}"|sed 's/\</cast(a./g'|sed 's/\>/as string/g'
but this is giving something little different than expected
castas string(aas string.abcas string, castas string(aas string.defas string
Upvotes: 1
Views: 114
Reputation: 785866
You can use awk
:
awk 'BEGIN{FS=OFS=", "} {for (i=1; i<=NF; i++) $i = "cast(" $i " as string)"} 1' <<< "$test"
cast(abc as string), cast(def as string)
Upvotes: 1