1

The following Javascript code doesn't pass a command string correctly:

cp = require("child_process");
var command = "awk < " + mypath + "\" \$3 ~ \"^rs\" {print \$3}\""
cp.exec(command, function (err, stdout, stderr) {});

Is there a more appropriate Node package or Javascript workaround for passing quotation marks and dollar signs to an Awk interpreter that gets invoked in a Bash environment when using child_process in Node?

SANBI samples
  • 1,590
  • 2
  • 12
  • 18
  • I haven't tried this myself, but this looks promising: http://stackoverflow.com/a/22827128/942223 – tiriana Dec 14 '15 at 09:04

2 Answers2

2

There is a native-Node awk package, consider using this instead.

djechlin
  • 54,898
  • 29
  • 144
  • 264
  • this awk package is bullshit, code is obfuscated and does not actually work, check the only issue. – Sw0ut Jan 18 '18 at 13:23
0

Hmm, if I am reading this correctly:

"awk < " + mypath + "\" \$3 ~ \"^rs\" {print \$3}\""

it suggests that your parameter order may need tweaking, i.e. start with simple awk:

awk '{print $0}' /some_file # print each line 

Taking the above (not clear) but do you mean something like:

awk '/^rs/ {print $3}' /some_file ##  

# for each line starting with 'rs' print 3rd variable?

Perhaps something like:

Ok, modified a bit; since I'm not familiar with the solution that you are 'calling from', then you will need to tweak appropriately.

"awk '/^rs/{print \$3}'" + "mypath"  ## ?

Or, perhaps (not sure if you need to escape $3):

"awk '/^rs/{print $3}'" + "mypath"  ## ?
Dale_Reagan
  • 1,629
  • 12
  • 10
  • Yes, the `mypath` variable includes the filename and I want to print the third column of each line starting with rs, but unfortunately the first backslash in your solution is indicated as the reason for throwing `SyntaxError: Unexpected token ILLEGAL`. – SANBI samples Dec 23 '15 at 20:46
  • Note, suggesting 'something like' - so above should be close enough to get you to a solution with some tinkering on your part - check the docs for your programming environment - it should specify what/how to 'format arguments'. :) – Dale_Reagan Dec 24 '15 at 22:08