大家下午好,我有两个这样的文件:
档案1
45.999 60.9999
70.000 23.0090
文件2
DATAFILE
pheno.txt
TRAITS
FIELDS_PASSED TO OUTPUT
WEIGHT(S)
RESIDUAL_VARIANCE
EFFECT
2 cross alpha
EFFECT
1 cross alpha
RANDOM
animal
FILE
pedigree.txt
SNP_FILE
snp_.txt
(CO)VARIANCES
并且需要为文件2的特定位置传递文件1的值,如下所示:
文件2
DATAFILE
pheno.txt
TRAITS
FIELDS_PASSED TO OUTPUT
WEIGHT(S)
RESIDUAL_VARIANCE
45.999
EFFECT
2 cross alpha
EFFECT
1 cross alpha
RANDOM
animal
FILE
pedigree.txt
SNP_FILE
snp_.txt
(CO)VARIANCES
23.0090
记住,我想保留文件2,只需添加文件1值
答案 0 :(得分:1)
set -- $(<file1)
sed -i "/RESIDUAL_VARIANCE/{n;c$1
};\${s/[0-9].*/$4/;t;a$4
}" file2
另见man sed
:
-i 就地编辑文件