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.

4
  • 3
    Yes this is a powershell problem, escape the double-quotes, i.e. jq -c .[] input.json | awk '{print > \"doc00\" NR \".json\";}' Commented Aug 31, 2021 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"? Commented Aug 31, 2021 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 to the linked duplicate for details. Commented Aug 31, 2021 at 20:40
  • 1
    @DanW, yes, you should be able to pass a file path to awk's > operator. Commented Aug 31, 2021 at 20:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.