1

Consider this awk script to print column #2 of every line: awk '{print $2}' a.txt. $2 is not a shell variable, yet when I attempt to submit this code to qsub, $2 is interpreted as such. I.e.

qsub awk '{print $2}' a.txt

results in qsub executing the command

awk '{print }' a.txt

To be clear, I'm not trying to use a shell variable in an awk script; therefore How do I use shell variables in an awk script? is not applicable.

I tried suggestions in Using awk with qsub and issues with quotations, including \$2 and

qsub -- awk '{print $2}' a.txt.

Neither works.

I can certainly put awk in a script and call qsub that way, i.e., qsub awkscript.sh. However, if there's a way to use qsub+awk from the command line, I'd like to learn how.

bamby
  • 11
  • 2
  • 1
    I've never heard of `qsub` but you could try `qsub "awk '{print \$2}' a.txt"` or `qsub 'awk \"{print \$2}\" a.txt'`. You may need to add or remove backslashes in front of the `$2`. – Ed Morton Mar 03 '21 at 00:29
  • Thanks for asking. None of these work, unfortunately. – bamby Mar 03 '21 at 00:37
  • I'm speachless, I'd never heard of `qsub`, but for @EdMorton -- now I know we are down in the weeds. So `qsub` (I have the man page), is the user utility to submit a script for background processing by a batch server. 21 years using Linux and I somehow have gotten along without it `:)` – David C. Rankin Mar 03 '21 at 03:50
  • It's fairly specific to high-performance computing batch environments, but pretty ubiquitous in those. – tripleee Mar 03 '21 at 05:56

2 Answers2

1

does a double-layer quoting work, like

qsub 'awk '\''{ print $2 }'\'' a.txt '
RARE Kpop Manifesto
  • 2,453
  • 3
  • 11
0

RARE Kpop Manifesto below was 99% correct. With a backslash, the whole expression worked like magic :)

qsub 'awk '\''{ print \$2 }'\'' a.txt '

bamby
  • 11
  • 2