.import in sqlite3 through prompt - import

I was trying to import a csv file through prompt doing:
.mode csv
.import 'filepath' table
but that didn't work ihave to put the csv file in the sqlite's .exe folder to work.
my question is why, can't i import a csv from another folder?
many thanks

So the way i found to not move the csv for sqlite's folder is to change the work directory:
To see in what directory you are in:
.shell cd
To change directory to the csv's folder:
.cd 'fullpath directory of csv you want'
Then just import the csv(you can use the relative path):
.import '.\name.csv' tablename

Related

How do I unzip multiple .gz files and output individual csv files contained in each of them?

Non of the threads give a complete answer to this task.. I have multiple .gz files in one directory, I want to be able to extract all the csv files in each of them and output individual csv files. my code below runs without error, but does not unzip any file. I can't figure out where the problem is
#unzipping .gz files
import gzip
import shutil
import pandas as pd
import glob, os
for filename in glob.iglob('C:/Users/shedez/Documents/Data/**', recursive=True):
if filename.endswith('gz'): # filter dirs
with gzip.open(filename, 'rb') as f_in:
with open('C:/Users/shedez/Documents/Data', 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)

Export to CSV from postgresql

I want to export a postgresql table to a csv file.
I have tried two ways, however both are unsuccessful for different reasons.
In the first case, you can see what I run and what I get bellow:
COPY demand.das_april18_pathprocess TO '/home/katerina/das_april18_pathprocess.csv' DELIMITER ',' CSV HEADER;
No such file or directory
SQL state: 58P01
I need to mention that in the location /home/katerina/ I have created an empty file named das_april18_pathprocess.csv, for which I modified the Permission settings to allow Read and Write.
In my second try, the query is executed without any errors but I cannot see the csv file. The command that I run is the following:
COPY demand.das_april18_pathprocess TO '/tmp/das_april18_pathprocess.csv' DELIMITER ',' CSV HEADER;
In the /tmp directory there is no cvs file.
Any advice on how to export the table to csv file with any way is really appreciated!
Ah, you run into a common problem -- you're creating a file on the server's filesystem, not your local filesystem. That can be a pain.
You can, however, COPY TO STDOUT, then redirect the result.
If you're using linux or another unix, the easiest way to do this is from the command line:
$ psql <connection options> -c "COPY demand.das_april18_pathprocess TO STDOUT (FORMAT CSV)" > das_april18_pathprocess.csv
copy ( select * from demand.das_april18_pathprocess) to '/home/katerina/das_april18_pathprocess.csv' with CSV header ;

mass import .csv files into postgresql

i am using Postgresql 9.4 and trying to import all files in a specific folder into and existing table using the following command:
COPY xxx_table FROM '/filepath/filename_*.csv' DELIMITER ',' CSV HEADER;
marking * as a variable part of the file name.
However it results in an error. I have found similar question on here however non of them is related to "COPY" command or alternatively using psql.
Any help on this would be highly appriciated.
Do you need first create the table manually, then:
Copy data from your CSV file to the table:
Example:
\copy zip_codes FROM '/path/to/csv/ZIP_CODES.txt' DELIMITER ',' CSV
You can also specify the columns to read:
Example:
\copy zip_codes(ZIP,CITY,STATE) FROM '/path/to/csv/ZIP_CODES.txt' DELIMITER ',' CSV

Copy .csv files in to one file with file name printed to allinone.csv

I have been given a data extract dump from an Oracle DB (cc&b). Each extract comes with a .log file which gives a table def, pk, fk, data types etc. I want to copy all these files in to one. I aware of the MS-Dos command
'copy *.log allinone.txt'
My problem is the content of the .log files do not contain the table name; the table name only exists on the file name. I need the table name printed in the allinone.txt file.
There are 486 tables so manual is not really ideal. Is there way to Print File Name + Content?
I'm assuming you are really using Windows, and not MS-DOS.
I'm also assuming all the .log files are in the same folder.
No batch file is required. Simply CD to the folder with the log files. Then run the following command:
type *.log >combinedLog.txt 2>&1
The TYPE command will include the file name at the top of each file output when a single command types multiple files. The file name is printed to stderr, so stderr is redirected to stdout (2>&1).

Create a batch file to copy and rename file

I need to write a batch file that copies a file to a new folder and renames it.
At the moment, my batch file consists of only this command:
COPY ABC.PDF \\Documents
As you can see, it only copies the file ABC.pdf to the network folder Documents.
However I need to change this so it renames the file ABCxxx.pdf, where xxx is a text variable that I would like to set somewhere in the batch file.
For example, if xxx = _Draft, then file would be renamed ABC_Draft.pdf after it is copied.
Make a bat file with the following in it:
copy /y C:\temp\log1k.txt C:\temp\log1k_copied.txt
However, I think there are issues if there are spaces in your directory names. Notice this was copied to the same directory, but that doesn't matter. If you want to see how it runs, make another bat file that calls the first and outputs to a log:
C:\temp\test.bat > C:\temp\test.log
(assuming the first bat file was called test.bat and was located in that directory)
type C:\temp\test.bat>C:\temp\test.log