我正在尝试追加并使用sed
为每个单词添加一些文字我的意见是:
abc, def
我期待输出为:
cast(abc as string), cast(def as string)
我正在尝试做类似的事情:
test='abc, def'
echo "${test}"|sed 's/\</cast(a./g'|sed 's/\>/as string/g'
但是这给出了与预期不同的东西
castas string(aas string.abcas string,castas string(aas string.defas 串
答案 0 :(得分:2)
您可以使用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)
答案 1 :(得分:1)
test='abc, def'
echo "${test}"|sed -r 's/\w+/cast(& as string)/g'