user3228734
user3228734

Reputation: 1

Copy and Paste of Files

How can I copy a selected part of one file (File 1) and paste to the second file (File 2) after some selected lines via script/commands? The result should be stored in File 3.

I have tried with echo but echo deletes existing content, so i am not getting the desired result.

File 1

111111
222222
333333
444444

File 2

aaaaa
bbbbb
ccccc
ddddd
fffff
.
.
.

File3

111111
222222
333333
444444
aaaaa
bbbbb
ccccc
ddddd
eeeee
fffff
.
.
.

Upvotes: 0

Views: 74

Answers (3)

arbulgazar
arbulgazar

Reputation: 1973

Basically if you need to paste all file1 before file2:

file1 > file3 && file2>>file3

If file1 after file2:

file2 > file3 && file1>>file3

The>symbol means you overwrite everything, then >> means you add after existing.

If you want to paste something specific, with echo, then you should use:

echo "Something" > file3
echo " good" >> file3

Makes you file with contents Something good

Upvotes: 0

Alfe
Alfe

Reputation: 59616

The well-known cat program derives its name from concatenate and is meant to be used for this:

cat file1 file2 > file3

It simply concatenates all files given by name as arguments and prints the result to stdout which you then can redirect into another file.

Upvotes: 1

olympia
olympia

Reputation: 352

Try:

cat file1 > file3

Followed by:

cat file2 >> file3

The double > allows to append to a file, not deleting existing content. Hope this helps!

Upvotes: 0

Related Questions