append to end to line without newline
By Emma Johnson •
When i try to append to the end of a file it creates a new line. Now I have tried to fix this with echo -n but that doenst work.
So what am I trying. I'm trying to get the following result:
Hello
This
Is
A
TestBut when I Append text with echo with
echo -n "Test2" >> file.txtThe following thing happens:
Hello
This
Is
A
Test
Test2But what I want is:
Hello
This
Is
A
Test Test2How am I able to do this? I have tried sed,echo and printf but none of these give the right result
01 Answer
With sed:
sed '$s/$/ Test2/' fileor
truncate -s-1 file
echo -n " Test2" >> fileOutput:
Hello This Is A Test Test28
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"