bash 如何在Bash中逐行合并两个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3806874/
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 two files line by line in Bash
提问by semteu
I have two text files, each of them contains an information by line such like that
我有两个文本文件,每个文件都包含一行信息,例如
file1.txt file2.txt
---------- ---------
linef11 linef21
linef12 linef22
linef13 linef23
. .
. .
. .
I would like to merge theses files lines by lines using a bash script in order to obtain:
我想使用 bash 脚本逐行合并这些文件以获得:
fileresult.txt
--------------
linef11 linef21
linef12 linef22
linef13 linef23
. .
. .
. .
How can this be done in Bash?
如何在 Bash 中做到这一点?
回答by ghostdog74
here's non-paste methods
这是非粘贴方法
awk
awk
awk 'BEGIN {OFS=" "}{
getline line < "file2"
print exec 6<"file2"
while read -r line
do
read -r f2line <&6
echo "${line}${f2line}"
done <"file1"
exec 6<&-
,line
} ' file1
Bash
重击
pr -tmJ a.txt b.txt > c.txt
回答by vtha
Try following.
尝试跟随。
man paste
回答by Christopher Creutzig
Check
查看
##代码##possible followed by some command like untabify
or tabs2spaces
可能后跟一些命令,如untabify
或tabs2spaces