在bash中按列组合文件和条件
我想按列组合bash中的几个在bash中按列组合文件和条件,bash,awk,concatenation,paste,Bash,Awk,Concatenation,Paste,我想按列组合bash中的几个txt文件。每个文件的名称file为一个模式,后跟一个数字。因此,File1.txtFile2.txtFile3.txt等等。下面3个文件将用作示例(但我有几个) 文件1: ######## infx infx infx ######## infx infx infx ####### infx infx probeset_id sample1 sample2 sample3 PR01 1 2 0 PR02
txt
文件。每个文件的名称file
为一个模式,后跟一个数字。因此,File1.txt
File2.txt
File3.txt
等等。下面3个文件将用作示例(但我有几个)
文件1:
######## infx infx infx
######## infx infx infx
####### infx infx
probeset_id sample1 sample2 sample3
PR01 1 2 0
PR02 -1 2 0
PR03 2 1 1
PR04 1 2 1
PR05 2 0 1'
文件2:
######## infx infx infx
######## infx infx infx
probeset_id sample4 sample5 sample6
PR01 2 2 1
PR02 2 -1 0
PR03 2 1 1
PR04 1 2 1
PR05 0 0 1'
文件3:
# The dfn
######## infx infx infx
######## infx infx infx
probeset_id samplen1 samplen2 samplen3
PR01 2 -1 1
PR02 1 -1 0
PR03 2 1 1
PR04 1 2 -1
PR05 0 2 1'
要完成以下output.txt:
$ head output.txt
probeset_id sample1 sample2 sample3 sample4 sample5 sample6 samplen1 samplen2 samplen3
1 PR01 1 2 0 2 2 1 2 -1 1
2 PR02 -1 2 0 2 -1 0 1 -1 0
3 PR03 2 1 1 2 1 1 2 1 1
4 PR04 1 2 1 1 2 1 1 2 -1
5 PR05 2 0 1 0 0 1 0 2 1
另外,文件之间带有
##
的行数可能不同。有什么办法解决这个问题吗?您可以使用下一个命令
join <(grep -v "^#" file1) <(grep -v "^#" file2) |
join - <(grep -v "^#" file3) | awk '{print (NR>1?NR-1:""), $0}'
加入
probeset_id sample1 sample2 sample3 sample4 sample5 sample6 samplen1 samplen2 samplen3
1 PR01 1 2 0 2 2 1 2 -1 1
2 PR02 -1 2 0 2 -1 0 1 -1 0
3 PR03 2 1 1 2 1 1 2 1 1
4 PR04 1 2 1 1 2 1 1 2 -1
5 PR05 2 0 1 0 0 1 0 2 1