简体   繁体   English

如何使用 shell 脚本将一个文件内容合并/附加到另一个文件

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

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我想合并 fileA 和 fileB 的内容,并且 FileA 内容应该是合并文件的第一行

I tried using paste and sort command... not not able to get required result any suggestions...我尝试使用pastesort命令...无法获得所需的结果任何建议...

cat FileA FileB > NewFile

or或者

cat FileA > NewFile
cat FileB >> NewFile

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.这会将file1和file2的内容放入file3中。

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 中已经存在的信息中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用脚本外壳将文件附加到具有合适格式的另一个文件中 - how can i append a file into another file with a suitable format using script shell 如何逐行比较 shell 脚本中一个文件的内容与另一个文件的内容? - How to compare content of one file to the another file in shell script line by line? 如何将一个文本文件的内容与另一个文本文件的第一行进行比较,并在shell脚本中的if语句中使用? - How to compare content of one text file with first line of another and use in if statement in shell script? 将 bash 脚本内容附加到另一个文件 - Append bash script content to another file 使用shell脚本合并txt文件的行 - merge lines of a txt file using shell script 如何在bash脚本中将包含“ &lt;&gt;”的一个文件附加到另一个文件 - How to append one file that includes '< >' to another in bash script 如何从文件中提取特定行并将其附加到Shell脚本中的另一个现有文件中,然后从原始文件中删除? - how to extract specific lines from file and append it to another existing file in shell script and then delete from original? 如何使用shell脚本对文本文件的内容进行排序 - How to sort a content of a text file using a shell script 使用Shell脚本搜索和替换文件内容 - Search and replace file content using shell script 使用 shell 脚本转换文件内容 - convert a file content using shell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM