简体   繁体   中英

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

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

cat FileA FileB > NewFile

or

cat FileA > NewFile
cat FileB >> NewFile

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM