SQLcl Oracle to export data to CSV without blank first line and without carriage return character at the end
Why don't you just use the UNLOAD TABLE command ?
sql -s scott/tiger@localhost:1521/spatialdb &lt;&lt;EOF
unload table us_cities
EOF

Or even this simple one-liner:
echo &quot;unload table us_cities&quot; | sql -s scott/tiger@localhost:1521/spatialdb

This creates file US_CITIES_DATA_TABLE.csv in your current directory.
Check the help about the UNLOAD command to get details about various options for formatting the output.