This version uses only bash parameter substitution to slice and dice paths. Pass it one or more absolute file paths:
#!/bin/env bash
for path; do
dir="${path%/*}"
dest="${dir%/*}"
dest="${dest%/*}"
cp "$path" "${dest}/${dest##*/}_${path##*/}"
done
Here is an expanded version. This one also accepts relative paths and the number of parent dirs to traverse is tunable:
#!/bin/env bash
# Each param for this script is the path of a file. It
# accepts relative paths if you have appropriate tool to
# robustly determine absolute paths (not trivial). Here
# we're using GNU 'realpath' tool.
#
# Usage: copy2up filepath1 [filepath2...]
# for converting relative paths to absolute
# if it's missing replace realpath with available tool
# (or just always use absolute path arguments)
pathtool=realpath
# directory levels upwards to copy files
levels=2
# iterate over each parameter
for path; do
if [[ ! $path =~ ^/ ]]; then
# convert relative to absolute
path="$($pathtool $path)"
fi
file="${path##*/}"
dir="${path%/*}"
dest=$dir
# chdir upwards 'levels' times to destination
for (( i=0; i<$levels; i++ )); do
dest="${dest%/*}"
done
# to be prepended to original filename
destpfx="${dest##*/}"
newpath="${dest}/${destpfx}_${file}"
cp "$path" "$newpath"
done
As for your specific use case, you could run this with find if that's how you are locating your 'F3.bam' files. For example:
find /some/path -name F3.bam -exec copy2up.sh {} +