M BUZZ CRAZE NEWS
// general

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
Test

But when I Append text with echo with

echo -n "Test2" >> file.txt

The following thing happens:

Hello
This
Is
A
Test
Test2

But what I want is:

Hello
This
Is
A
Test Test2

How am I able to do this? I have tried sed,echo and printf but none of these give the right result

0

1 Answer

With sed:

sed '$s/$/ Test2/' file

or

truncate -s-1 file
echo -n " Test2" >> file

Output:

Hello
This
Is
A
Test Test2
8

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy