Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j - export cypher query file results to .csv or .txt file via the Neo4jShell

I have a .cql query file that I want to run from the Neo4jShell (Windows) with the command:

Neo4j> Neo4jShell -file query.cql

The query returns some rows of data. How can I write that query output into a .csv or .txt file from the shell?

Also, I am using the Windows command prompt so take that into consideration with any solutions. Thanks!

UPDATE 1:

The command suggested by Luane essentially works:

Neo4j> Neo4jShell -file query.cql > out.csv

The only issue is that the output isn't comma separated:

+--------------------------+
| column 1    | column 2   |
+--------------------------+
| "C1611640"  | "C1265875" |
| "C1579268"  | "C1265875" |
| "C1570906"  | "C1265875" |
| "C1522577"  | "C1265875" |
| "C1519033"  | "C1265875" |
| "C1515119"  | "C1265875" |
|      .             .     |
|      .             .     |
|      .             .     |
| "C1533658"  | "C1265875" |
| "C1532338"  | "C1265875" |
| "C1527144"  | "C1265875" |
+--------------------------+
2000 rows
219 ms
like image 515
Sergei Wallace Avatar asked Jan 01 '26 05:01

Sergei Wallace


1 Answers

Assuming your query returns data in the format you require, you can just send the output to any file. This works on MacOS, but I don't see why it should not work on Windows:

> neo4j-shell -file query.cql > out.txt
like image 61
Luanne Avatar answered Jan 04 '26 14:01

Luanne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!