I am trying to run a command which is something like this

intersectBed -a yeast.v2.bed -b cov.txt -wa -wb | awk -v OFS="\t" '{print $7,$8,$9,$6,$11,$10}' > out.txt

out.txt looks like this

chrI    151006  151096  0
chrI    142253  142619  53
chrI    87387   87500   8

I am working on the cluster and when I qsub the above command(that is submitting to the cluster) I get the out.txt file like this


The command line I am using with qsub is this:

qsub -l h_vmem=4G -cwd -j y -b y -N test "intersectBed -a yeast.v2.bed -b cov.txt -wa -wb | awk -v OFS="\t" '{print \$7,\$8,\$9,\$6,\$11,\$10}' > out.txt"

As you can see I have to escape each column($) with back slash so that shell does not consider it as its on variable. But some how tab does not work. Can anyone tell me what is going on here. Of course I can use sed 's/t/\t/g' after the awk command but I need to understand what is going on here and why does it not work.

Thanks in advance

  • 2
    You forgot to escape the inner double quotes for -v OFS="\t" (or use single quotes instead). SE syntax highlighting gives you a clue. Commented Mar 15, 2017 at 16:25

1 Answer 1


You're doing:

 qsub ... "intersectBed  ... -v OFS="\t"...more double-quoted text"

So that \t is outside the double quotes. For the shell, outside of quotes, \ is another quoting operator. There \t is like 't' or "t", so just t.

You're actually doing awk -v OFS=t.


 qsub... "inter... | awk -v OFS='\t' '{print \$7,\$8,\$9,\$6,\$11,\$10}' > out.txt"

Or, to worry only about single-quote characters:

 qsub... 'inter... | awk -v OFS="\t" '\''{print $7,$8,$9,$6,$11,$10}'\'' > out.txt'

set -x is your friend to investigate this kind of quoting issue.

  • Hi Stepahane, that worked pretty well. Where should I put set -x so as to see quoting issue and what will it output. Thanks for the help Commented Mar 15, 2017 at 16:54
  • Also when I use $7,$8,$9 in awk on command line it is fine but with qsub I have to escape it, but isn't it is still inside awk quotes?? Commented Mar 15, 2017 at 17:06
  • @user3138373, in qsub ... "inter...'...$1...'...", $1 (and ') is inside double-quotes. Shells expand parameters inside double-quotes (echo "$1" outputs the content of the first positional parameter), not inside single quotes (echo '$1' outputs $1) which is why we don't need the backslash in the second example above). Commented Mar 15, 2017 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .