0

I am using a shell script like the following to spool two columns(fields) of a particular table into a csv file as follow:

#!/usr/bin/bash

FILE="emp.csv"

sqlplus -s scott/tiger@XE  <<EOF

SET PAGESIZE 50000
SET COLSEP ","
SET LINESIZE 200
SET FEEDBACK OFF

SPOOL $FILE

SELECT name,city FROM EMP;

SPOOL OFF
EXIT
EOF

But the resulting csv file is becoming too large for my editor to open. Is there any way by which I can split the records into multiple csv files which are smaller and can be opened ? Can I use some counter such that when it exceeds a particular value the data is spooled to another file ?

  • use another editor to open the big file – Ipor Sircer Sep 8 '16 at 2:44
  • can you pipe the output through the split command? – Skaperen Sep 8 '16 at 2:55
2
cat emp.csv | split -l 6000

will create a bunch of little files: in this case 6000 lines long. The default is xaa, xab, and so on but you can change that: see the man page for split.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.