3

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...

upog
  • 4,965
  • 8
  • 42
  • 81

3 Answers3

12
cat FileA FileB > NewFile

or

cat FileA > NewFile
cat FileB >> NewFile
TypeIA
  • 16,916
  • 1
  • 38
  • 52
7

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

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
1

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
rok
  • 9,403
  • 17
  • 70
  • 126
  • `cat FileA | tee -a FileB > /dev/null` add `/dev/null` to suppress the cat of FileA, tee being ...well... tee. It is possible to make a temporary file and copy over FileB instead but this is simple. – DKebler Apr 20 '23 at 14:24