0

How do a add a new line to an existing .txt file, that consists of a text string, a tab, and a value of another text file?

Precisely, I have a text file test1.txt that looks like this:

A    B

and a test2.txt file that only contains the number value 100.

What I want to do is to use a command by which I would edit the test1.txt file, and make it look like this:

A    B
C    100

I've tried using the following command:

echo -e "C \t" test2.txt>>test1.txt.

I know that by using the command

test2.txt>>test1.txt

I will add a new row to test1.txt, with the value of 100, but what I'm trying to do is to add that value as a next column as I wish to make a table with data.

0
{ printf %s $'C\t'; cat test2.txt; } >>test1.txt

or

( printf %s $'C\t'; cat test2.txt ) >>test1.txt

or

printf %s $'C\t' >>test1.txt
cat test2.txt    >>test1.txt

or in bash

{ printf %s $'C\t'"$(<test2.txt)"; } >>test1.txt

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.