how to merge/append one file content to another file using shell script

13.7k views Asked by At

I have two file fileA and fileB

FileA content

PersonName Value1 Value2 Value3

FileB content

ALBERT check1 check1 check1
ALBERT check2 check2 check2
ALBERT check3 check3 check3

I want to merge content of fileA and fileB and FileA content should be the first line in the merged file

I tried using paste and sort command... not not able to get required result any suggestions...

3

There are 3 answers

2
TypeIA On BEST ANSWER
cat FileA FileB > NewFile

or

cat FileA > NewFile
cat FileB >> NewFile
0
user3157610 On

In Unix/Linux you can use the command cat

Example:

cat file1.txt file2.txt > file3.txt

This will put the contents of file1 and file2 into file3.

cat file1.txt >> file2.txt

This will add the information from file1.txt to the information already existing in file2.txt

1
rokpoto.com On

cat FileA | tee -a FileB

$ cat FileA
PersonName Value1 Value2 Value3
$ cat FileB
ALBERT check1 check1 check1
ALBERT check2 check2 check2
ALBERT check3 check3 check3
$ cat FileA | tee -a FileB
ALBERT check1 check1 check1
ALBERT check2 check2 check2
ALBERT check3 check3 check3
PersonName Value1 Value2 Value3