I have a Teradata bteq script exporting table definitions by running show table from a linux server. My problem is the script outputs the ddl into a file with new lines (^M) in each line and random characters at the beginning of the script. I can post process the file with linux commands to remove ^M. But since the characters at the beginning of the files are random it is difficult to code to remove them.
Script below:
#!/bin/sh
#########################################
DATADIR=[directoryname]
bteq <<EOI
.logmech LDAP
.LOGON server/user/pass;
.EXPORT DATA FILE=$DATADIR/script.sql
SHOW TABLE mydatabasename.mytablename;
.EXPORT RESET;
.IF ERRORCODE <> 0 THEN .EXIT ERRORCODE;
.LOGOFF
.EXIT
EOI
#########################################
First line of the export looks like below:
a^E_^ECREATE MULTISET TABLE mydatabasename.mytablename ,FALLBACK ,^M
Is there something I can do in the script to avoid getting the special characters?
Related
I would like to use the main database file location in function (replace or other) as input data. How can i get it?
for example: replace('c:\temp\main.db','main.db','')
I'm creating a database script for command line use under win10.
.database command result seems to be fine, but how to use in replace input?
EDIT: I have to use the location as variable, because i run the script from command line, recursively in a lot of directories with a lot of small databases, so i can't use constant value in replace.
The cmd line command:
forfiles /p c:\temp /m files.db /s /c "cmd /c c:\sqlite3.exe #path < c:\BookDbDataCopy.txt"
I want to use the path in the select as variable.
I got it :)
create table path (a text);
.mode csv
.output 'c:\data.csv'
.databases
.import 'c:\data.csv' path
The solution:
- create a table for the path
- write the command output in file
- import the file in table
- select the table in replace variable :)
select replace((select a from path where a like 'main%'),'main: c:\',''), t.* from path;
I am using SQLite and I can't import this csv file for some reason. I ran cmd first then entered SQLite.
my input in cmd:
cd C:\Users\Fries\Desktop\SQLite
sqlite3
.mode csv
.import C:\Users\Fries\Desktop\city.csv cities
.schema cities
I am using this tutorial. http://www.sqlitetutorial.net/sqlite-import-csv/
for some reason I can't open the csv
I am new to dbms and sqlite seems to be a super simple one
Going by the feedback in the error message, it looks like the backslashes need to be escaped. I would first try this:
sqlite> .import C:/Users/Fries/Desktop/city.csv
The following might also work, using escaped backslashes:
sqlite> .import C:\\Users\\Fries\\Desktop\\city.csv
Everytime I start SQLite, I have to re-turn on headers, re-switch to column mode, re-change the separator and/or width. How can I make the settings persist??
Repeated Code
.mode column
.headers on
.separator ','
In other words, how can I save the settings so that next time I run SQLite, my preferences are automatically applied.
Create a .sqliterc file in your home directory
Ah, finally stumbled upon the answer. You can create a .sqliterc (SQLite Run Commands file) in your home directory. Every time you run sqlite, it will load the settings from the rc file.
Here's a quick command line script you can paste in the terminal for some basic settings (edit it to add additional preferences):
cat << EOF > ~/.sqliterc
.headers on
.mode column
EOF
There are alternative command line options. Something like this:
alias mysqlite='sqlite3 -column -header -separator ,'
I'm trying to export a csv file to a fixed length file.
I'm using SQLite because I have to process the file.
The problem I'm having is with the output.
Here is the code I am running from a sql file:
.output stdout --send output to screen
.echo off
.headers off
.separator ','
.mode column
.open tmp.db
DROP TABLE IF EXISTS myData;
.import 'C:\2015.csv' myData
.width 4 4 1 6 16 2 6
.output myData.txt --send output to file
select * from myData;
.output stdout --send output back to screen
.print "File was created."
DROP TABLE IF EXISTS myData;
vacuum;
.print "tmp.db vacuum complete"
.print "Type '.exit' or '.quit' to exit SQLite"
.exit
The problem is that in the first line, where I send the output to the screen, I get an error:
Error: unknown command or invalid arguments: "output". Enter ".help"
for help
The script executes, but it actually displays the results of the sql (and it also writes them to the file).
However, if I run every single command from the sqlite console, everything works fine. I only get the error when I run it from the SQLite console using .read
Any suggestions? What am I missing? I checked the docs in the SQLite website, and in the example presented they switch the output from console to file and back in the same manner.
Thank you.
I think I found the problem:
.output stdout --send output to screen
Apparently, the --send... was interpreted as an argument. Removing the -- and the comments after stdout fixed the problem.
Thanks!
The .output command expects a single parameter, not five.
This forms works fine:
.output stdout
I have a text file which contains an sqlite statment where I want to dump it into .sql format but not able to excute it. Any help would be appreciated. My file is stored on desktop as verbali.txt and when i go to command prompt and to specific sqlite folder and run it just open the text file .
.mode insert
.header on
.out file.sql
select select Id ,CompanyId ,DateTime ,Serial ,DeviceId ,AgentAId ,GpsAddress ,Targa ,CommonRoadDescription ,RoadCivicNumber ,VehicleBrandDescription ,VehicleModelDescription ,VerbaliVehicleTypeDescription ,CommonColorVehicleDescription ,VerbaliRuleOneCode ,VerbaliRuleOneDescription ,VerbaliRuleOnePoints ,VerbaliClosedNoteDescription ,Points ,VerbaliMissedNotificationDescription ,MissedNotificationNote ,StatementNote from VerbaliData
Pipe the file to sqlite3, in command prompt:
sqlite3 yourdatabase.db <path\to\verbali.txt
where sqlite3 is the sqlite3.exe command line tool.