I have the following command:
echo "column1, column2, column3" > test.csv && cat data.json | jq -r '. | [.["column1"], .["column2"], .["column3"]] | @csv’ >> test.csv
echo "column1, column2, column3" > test.csv &&
cat data.json | jq -r '. | [.["column1"], .["column2"], .["column3"]] | @csv’ >> test.csv
itIt creates a column headings and the data from data.jsondata.json.
I
I am trying to also add it where for example it only would pull data that contains the words ("abc""abc") from column3column3.
I added:
|select(.column3| startswith ('ab'))
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
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 `('
-bash: syntax error near unexpected token `('
my json.data looks like this: { "column1": "hello", "column2": "bye", "column3": "abc" }
{
"column1": "hello",
"column2": "bye",
"column3": "abc"
}
How do I parse column3column3? Not sure what I am doing wrong. Thank you!