![如何在多行变量的每一行前面添加文本?](https://linux22.com/image/126796/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%A4%9A%E8%A1%8C%E5%8F%98%E9%87%8F%E7%9A%84%E6%AF%8F%E4%B8%80%E8%A1%8C%E5%89%8D%E9%9D%A2%E6%B7%BB%E5%8A%A0%E6%96%87%E6%9C%AC%EF%BC%9F.png)
我打印所有变量及其值
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
答案1
$ 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