Bash
如何將文本添加到多行變數的每一行?
我用那裡的值列印所有變數
echo "$val" mapreduce.map.memory.mb,3584 mapreduce.map.java.opts,-Xmx2560m mapreduce.reduce.memory.mb,3584 mapreduce.reduce.java.opts,-Xmx2560m mapreduce.task.io.sort.mb,1280
如何在每行的開頭附加單詞 - type_config
所以輸出將如下
type_config,mapreduce.map.memory.mb,3584 type_config,mapreduce.map.java.opts,-Xmx2560m type_config,mapreduce.reduce.memory.mb,3584 type_config,mapreduce.reduce.java.opts,-Xmx2560m type_config,mapreduce.task.io.sort.mb,1280
$ echo "$val" | sed 's/^/type_config,/g'
輸出:
type_config,mapreduce.map.memory.mb,3584 type_config,mapreduce.map.java.opts,-Xmx2560m type_config,mapreduce.reduce.memory.mb,3584 type_config,mapreduce.reduce.java.opts,-Xmx2560m type_config,mapreduce.task.io.sort.mb,1280