#!/bin/bash

if [ "$#" -eq 0 ]; then
  echo "No hosts" >&2
  exit 1
fi

if [ "$1" == "-H" ]; then
  filter() {
    while read -r line; do echo "$1:$line"; done
  }
  shift
else
  filter() {
    cat
  }
fi

file="$1"
shift
hosts=("$@")

for host in "${hosts[@]}"; do
  scp -q "$host:$file" /dev/stdout 2>/dev/null | filter "$host"
done
