bash 如何使用shell脚本将一个文件内容合并/附加到另一个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20906734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to merge/append one file content to another file using shell script
提问by upog
I have two file fileA and fileB
我有两个文件 fileA 和 fileB
FileA
content
FileA
内容
PersonName Value1 Value2 Value3
FileB
content
FileB
内容
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
我想合并文件A和文件B的内容,文件A内容应该是合并文件的第一行
I tried using paste
and sort
command... not not able to get required result
any suggestions...
我尝试使用paste
和sort
命令...无法获得所需的结果任何建议...
回答by TypeIA
cat FileA FileB > NewFile
or
或者
cat FileA > NewFile
cat FileB >> NewFile
回答by user3157610
In Unix/Linux you can use the command cat
在 Unix/Linux 中你可以使用命令 cat
Example:
例子:
cat file1.txt file2.txt > file3.txt
This will put the contents of file1 and file2 into file3.
这会将文件 1 和文件 2 的内容放入文件 3 中。
cat file1.txt >> file2.txt
This will add the information from file1.txt to the information already existing in file2.txt
这会将 file1.txt 中的信息添加到 file2.txt 中已经存在的信息中