#!/bin/bash

# Usage: $0 ./Full_Path/comments.txt

# Add the first path component, "Full_Path" in the above example, as a
# header of the text file. Skip the operation if the header is already
# present.

for FILE in "$@"
do
    BASE=$(basename "$FILE")
    HEADER=$(basename "$(dirname "$FILE")")/"${BASE}"
    if ! grep -q "${HEADER}" "${FILE}"
    then
        echo $0: addign header to "'${FILE}'"
        echo "${HEADER}" | cat - "${FILE}" | sponge "${FILE}"
    fi
done
