I have this command line:
curl https://token-api/42 | awk '{ print $0 }'
which produces this output:
{"id":"PX-12345","expiresAtUtc":"2020-07-05T06:55:52","createdUtc":"2019-07-15T06:55:52"}
The awk '{ print $0 }' is there to ensure there is a newline appended at the end of the output.
Now I want to do the same but for a csv list of user ids (users.csv) instead of a hard-coded 42 by using xargs. So I tried this and a number of variations:
awk -F, '{print "curl https://token-api/$0 | awk \'''\''{ print $0 }\'''\''"}' < users.csv | xargs -P1 -I {} sh -c '{}'
This produces the following error:
awk: cmd. line:1: warning: escape sequence `\'' treated as plain `''
awk: cmd. line:1: {
awk: cmd. line:1: ^ unexpected newline or end of string
If I remove the xargs part, I get the following output:
curl https://token-api/$0 | awk '{ print $0 }'
which is passed to xargs. I guess my problem is with the $0 that is used twice but I have no idea to escape this.
If there is another (better) way to append a newline to the output of curl, that might help too because without that it's working fine. However, then I get a long list of unseparated JSON documents as output like this:
{"id":"PX-12345","expiresAtUtc":"...","createdUtc":"..."}{"id":"PX-12346","expiresAtUtc":"...","createdUtc":"..."}{"id":"PX-12347","expiresAtUtc":"...","createdUtc":"..."}
curl?{ curl http://foo.com/bar; echo; }.users.csvlook like?echoworks, I was making it too complex I guess. Thanks!!