First of all, it's easy to simply point out that the method is a bit redundant. But one thing at a time...
When using cat <<EOF
, anything within that can be parsed as an inline command or substitution will be parsed as such. That means that stuff like $1
and $(...)
will first be evaluated before the heredoc is created. If you wish to avoid that, the easiest option is to single quote the EOF
as such:
cat <<'EOF'
heredoc string stuff in here
EOF
But I'm not sure that is what you want. For whatever you wish to appear in a file, just pipe it there:
cat $FILEA $FILEB | sort -k1,1 -k2,2n | mergeBed -i - | awk -F\\t '{print $1 "\t" NR "\t\t" $2 "\t" $3 "\t\t.\t\t" NR}' > unionpeaks.gff
The heredoc is not necessary. Now, let's look at the cammand per se:
sort -k1,1 -k2,2n -- "$FILEA" "FILEB" | mergeBed -i - | awk -v FS="\t" -v OFS="\t" '{ print $1, NR, "", $2, $3, "", ".", "", NR }' > unionpeaks.gff
cat
is simply unnessecary. sort
can take file names as input, so no need for an extra call -- I just added a --
to make sure that it doesn't break with files that start with a -
(dash). Also, it seems you want tab delimited, so set the OFS
(output field separator) to tab. The expected delimiter seems a bit weird as you want double tab for some of them, hence the use of zero-byte strings, i.e. ""
.
If you simply want that command in a script, then just edit a script file to conatain the script. Combine the EOF
learning with the script improvement if the learning about heredocs is the intended purpose. :)