0

For Example we have the following files:

$ ls
$ test1 test2 random
$ cat test1
This is a test file
$ cat test2
This is another test file
$ cat random
This is a random file
$

Now I want to preserve the original content of random and append to it the contents of test1 and test2 so that I get

$ cat random
This a random file
This is a test file
This is another test file
$

I tried the following method:

$ cat test1 test2 > random
$ cat random
This is a test file
This is another test file
$

Second method which I tried:

$ cat test1 test2 random > random
cat: random: input file is output file

So how can I get the desired output?

4

You need to use the following code:

$ cat test1 test2 >> random
$ cat random
This is a random file
This is a test file
This is another test file
$
0

You asked specifically for a cat solution, but here's how zsh could achieve the same end result, without having to invoke any actual commands.

% <test1 <test2 >>random
%
  • Yes it is one of the many ways to achieve the result, but here OP intends to know if this result can be achieved using cat command or not? – Sonevol Jul 18 '17 at 19:02

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.