1

When using the following example from this question https://stackoverflow.com/a/48801628/3233462

jq -c  .[] input.json | awk '{print > "doc00" NR ".json";}

I get the following error:

enter image description here

I am a newbie to Powershell/jq/awk but all google searches point to using jq as the best way to resolve this.

Can anyone explain why I am getting this error and what I need to do to resolve it. It seems like a simple syntax error (maybe . needs escaping?). Nothing I have tried has resolved the issue.

To add some context, I have a json file with 2000+ objects in an array. I am trying to separate these using jq - this part seems to work. Then I am trying to output them to files (ideally named with the "name" property of each object) using awk.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Dan W
  • 365
  • 1
  • 4
  • 20
  • 3
    Yes this is a powershell problem, escape the double-quotes, i.e. `jq -c .[] input.json | awk '{print > \"doc00\" NR \".json\";}'` – Inian Aug 31 '21 at 18:25
  • @Inian awesome. I thought it must be something simple. Just a quirk of powershell I wasn't aware of. If I wanted to point the output to different location than the GnuWin32\bin, can I just add that path before the "doc00"? – Dan W Aug 31 '21 at 18:37
  • 1
    As Inian notes, the sad reality as of PowerShell 7.1 is that an _extra, manual_ layer of `\ `-escaping of embedded `"` characters is required in arguments passed to _external programs_. See [this answer](https://stackoverflow.com/a/59036879/45375) to the linked duplicate for details. – mklement0 Aug 31 '21 at 20:40
  • 1
    @DanW, yes, you should be able to pass a file _path_ to `awk`'s `>` operator. – mklement0 Aug 31 '21 at 20:42

0 Answers0