I have the following command:
echo "column1, column2, column3" > test.csv &&
cat data.json | jq -r '. | [.["column1"], .["column2"], .["column3"]] | @csv’ >> test.csv
It creates a column headings and the data from data.json.
I am trying to also add it where for example it only would pull data that contains the words ("abc") from column3.
I added |select(.column3| startswith ('ab')) so the full command is:
echo "column1, column2, column3" > test.csv &&
cat data.json | jq -r '. | [.["column1"], .["column2"], .["column3"]] |select(.column3| startswith ('ab')) | @csv’ >> test.csv
but I get the following error:
-bash: syntax error near unexpected token `('
my json.data looks like this:
{
"column1": "hello",
"column2": "bye",
"column3": "abc"
}
How do I parse column3? Not sure what I am doing wrong.
I added:where and how did you add it? Please post the full command that you have tried. Please post sample data fromdata.json, enough so others can test it.data.json-- one that is both illustrative and sufficient to replicate the error.