-1

I would like to paste/ merge pairs of files that share the same suffix (eg. "_file12345.tsv" as below) from two different directories that have the same length, to make one combined file.

I can't quite work out how to 'if file suffix in dir_1/ matches suffix in dir_2/, then paste together, then repeat for all matching pairs. Can't quite work out how to loop/ repeat for all the pairs (approx. 100 pairs of files).

> cat dir_1/unlabelled_file12345.tsv
0  15  20  25
0  20  40  50
0  10  12  15

> cat dir_2/labels_for_file12345.tsv
label1  info1
label2  info2
label3  info3

> bash some_merging_script.sh

> cat merged_file12345.tsv
label1  info1  0  15  20  25
label2  info2  0  20  40  50
label3  info3  0  10  12  15
John Kugelman
  • 349,597
  • 67
  • 533
  • 578

1 Answers1

0

This may be what you're trying to do

for file in dir_1/*_*.tsv; do
    suffix=_${file##*_}
    paste dir_2/*"$suffix" "$file" > merged"$suffix" || rm -f merged"$suffix"
done
M. Nejat Aydin
  • 9,597
  • 1
  • 7
  • 17