如何在shell脚本中将结果追加到列中



我正在尝试使用以下脚本合并两个intput文件以生成以下输出数据,但不知道如何将结果添加到第二列:

#!/bin/bash
while read gene number
do
while read gene2 type
do
if [ "$gene" = "$gene2" ]
then
echo -e "$genet$numbert$type" >>output.txt
elif [ "$gene" = "$type" ]
then
??? add the numbers in the second column >>output.txt
fi
done<in2.txt
done<in1.txt

这是我的输入文件:

in1.txt:

gene1   30
gene2   20
f   1
e   2

in2.txt:

gene1   f
gene2   e

期望输出:

output.txt:

gene1   30  f  1
gene2   20  e  2

使用bash和两个关联数组(in1,in2(:

#!/bin/bash
declare -A in1 in2
# read both files in associative arrays
while IFS=$'t' read -r key value; do in1[$key]="$value"; done < in1.txt
while IFS=$'t' read -r key value; do in2[$key]="$value"; done < in2.txt
# if necessary show both associative arrays
#declare -p in1 in2
# iterate over keys of associative array in2 and output data
for i in "${!in2[@]}"; do
echo -e "$it${in1[$i]}t${in2[$i]}t${in1[${in2[$i]}]}"
done

输出:

基因2 20 e 2gene1 30 f1

相关内容

  • 没有找到相关文章

最新更新