我有一个转换文件数据的脚本,为了更有效地工作,我想改变内存中的数据,然后将其转储到文件中.
我希望修改包含此文件的文件:
> This is a line
> this is other line
我使用sed命令来替换’>’带’#’的符号:
transform_output=$(eval "sed ${sed_args[@]} $file" 2>&1)
echo -e $transform_output
我得到输出:
# This is a line # this is other line
而不是我想要的输出是:
# This is a line
# this is other line
>如何将输出保存在保持换行符的字符串变量中?
>如何在包含“#ADDED LINE#”的变量的开头添加一行并将其保存在文件中?
(我想要获取的文件):
#ADDED LINE#
# This is a line
# this is other line
提前致谢
解决方法:
>引用用于防止在空白处分词:
echo -e“$transform_output”
>使用另一个echo对命令进行分组:
{echo“#ADDED LINE#”; echo -e“$transform_output”}>文件
标签:bash,linux
来源: https://codeday.me/bug/20190620/1245794.html