Reputation: 2585
I have a script that transforms a file's data, in order to work more efficiently I want to alter the data in memory and then dump it to the file. Supose I want to modify a file that contains this:
> This is a line
> this is other line
I use a sed command to replace the '>' symbols with '#' ones:
transform_output=$(eval "sed ${sed_args[@]} $file" 2>&1)
echo -e $transform_output
I get the output:
# This is a line # this is other line
rather than the output I would like to have wich is:
# This is a line
# this is other line
(the file I want to obtain would be):
#ADDED LINE#
# This is a line
# this is other line
Thanks in advance
Upvotes: 5
Views: 4816
Reputation: 782683
Quoting is used to prevent word-splitting at whitespace:
echo -e "$transform_output"
Group the command with another echo:
{ echo "#ADDED LINE#"; echo -e "$transform_output" } > file
Upvotes: 6