rmv
rmv

Reputation: 3235

Formatting Neo4J-Shell cypher query results?

Is there an option to export the results of a Neo4J-Shell cypher query in a comma-separated-value format, i.e. instead of

echo "START n=node(*)  MATCH n-[r]->m  RETURN n.value, type(r), m.value  ORDER BY n.value, type(r), m.value;"  |  neo4j-shell -v  -path neo4j-database/   >  /tmp/output.csv

less  /tmp/output.csv
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| n.value                                                 | type(r)                                           | m.value                                                       |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa" | "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" | "http://www.w3.org/2002/07/owl#Class"                         |
| "http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa" | "http://www.w3.org/2000/01/rdf-schema#label"      | "Rosa"                                                        |
| "http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa" | "http://www.w3.org/2000/01/rdf-schema#subClassOf" | "http://www.co-ode.org/ontologies/pizza/pizza.owl#NamedPizza" |
...

i would like to get the following output

less  /tmp/output.csv

"http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://www.w3.org/2002/07/owl#Class"                        
"http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa", "http://www.w3.org/2000/01/rdf-schema#label", "Rosa"                                                        
"http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa", "http://www.w3.org/2000/01/rdf-schema#subClassOf", "http://www.co-ode.org/ontologies/pizza/pizza.owl#NamedPizza" 
...

like in MySQL, where the ascii table is omitted when the client is used by an echo command from the shell.

Upvotes: 3

Views: 1598

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39915

  1. You can use neo4j-JDBC to run your cypher queries via JDBC. With that in place you can use any JBCD tool that allows you to create csv.
  2. Use the groovy script from https://gist.github.com/5736410

Upvotes: 2

Related Questions