Объединение столбцов из файлов, если они содержат совпадение в другом столбце

#!/bin/bash

if [[ "$#" != 0 ]]; then
  # only process the names given to us
  wc -l "$@"
  exit
fi

# process all regular files in this directory, avoiding this script
for f in ./*; do
    if [[ "$f" != "$0" ]] && [[ -f "$f" ]]; then
        wc -l "$f"
    fi
done
1
07.03.2016, 17:05
2 ответа

Я нашел решение:

awk -F "\t" 'FNR==NR {a[$1] = $2 "\t" $3;next} $5 in a{print $0 "\t" a[$5]}' file2.txt file1.txt > outing.txt
1
27.01.2020, 23:26

Вы можете сделать:

join -1 5 -2 1 -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,2.3 file1.txt file2.txt

Пример:

% cat f1.txt 
30    40    A    T    match1    string1
45    65    G    R    match2    string2
50    78    C    Y    match3    string3

% cat f2.txt 
match1    60    add1    50    add2
match2    15    add1    60    add2
match3    20    add1    45    add2

% join -1 5 -2 1 -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,2.3 f1.txt f2.txt
30 40 A T match1 string1 60 add1
45 65 G R match2 string2 15 add1
50 78 C Y match3 string3 20 add1
2
27.01.2020, 23:26

Теги

Похожие вопросы