1.

Solve : Space in Output File?

Answer»

Hi! I'm using DOS on Windows XP. My database is PostgreSQL 8.2. I've been trying to code a small export process. My .bat runs a .sql that contains some basic select statements. The output is catted to a .txt file. However, every record (header, detail and trailer) in the .txt file contains a space as the first byte. I don't think the space is generated by the SQL as there is no space in the output when I cat the data to a temp table. I cannot figure out why a space is being INSERTED as the first byte of the .txt file. Any thoughts? The .bat code is below.

set PGDB=test_works
set PGUSER=postgres
set PGPASSWORD=test
set PGPATH=C:\Program Files\PostgreSQL\8.2\bin\
set BASEDIR=C:\TEAMS
set DATADIR=%BASEDIR%\OUTPUT\
set SCRIPTDIR=%BASEDIR%\SCRIPTS\
set LOGDIR=%BASEDIR%\LOGS\

SET dtOnly=%1
IF NOT DEFINED dtOnly call getDateTime.bat
echo %dtOnly% > tmpFile

"%PGPATH%psql.exe" %PGDB% -U %PGUSER% -f "%SCRIPTDIR%SetExpDate.sql" -q -t

"%PGPATH%psql.exe" %PGDB% -U %PGUSER% -f "%SCRIPTDIR%TEAMS_EXPORT_EV.sql" -L "%LOGDIR%TEAMS_EXPORT_EV%dtOnly%.log" -q -t -o "%DATADIR%TEAMS_EXPORT_EV%dtOnly%.txt" >> "%LOGDIR%TEAMS_EXPORT_EV%dtOnly%.err" 2>&1
del tmpFileyou MEAN the txt looks like:

Code: [Select]
data
data
...
and you dont want this space at begining ?

if so maybe at first time %dtOnly% is set to null so it outputs blank LINE ?Hi! Thx so much for replying to my question!!!! Regarding the ouput... It's not actually a blank line of data at the top of the file. The code is putting a space in the first byte of each output row. I've added an example of the output below... There should be no space before the H, D or T on each row. I think the problem might be caused by the batch parms in the .bat code? I thought if i removed the -L that the problem would be fixed, but it doesn't seem to fix it.

HCOLORADO 045VRH 20081209
DCOLORADO 0451000117027
DCOLORADO 0451000118045
TCOLORADO 0450002


is this your completed script ? post all becouse i cant see any errors in this oneInstead of:
Code: [Select]echo hello > hello.txtuse:
Code: [Select]echo hello>hello.txtThe space between the first hello and the > is making it echo a space in your file.
Goodluck
Hey, All! Just wanted to say THX for taking time to evaluate this issue. I decided to change my SQL code so my data gets written to a temp table, and then I used a COPY TO in my SQL to generate the necessary output file. This eliminated the space in the first byte of each row. This might be a PostgreSQL issue that is caused when the output from a SELECT is catted to an external file. THX for everyone's time and attention! My way was the quickest fix, but never mind.Quote from: Jacob on December 10, 2008, 09:22:10 AM

My way was the quickest fix, but never mind.

Never mind indeed! His problem was a space at the beginning of each line. Your "solution" is for a space at the END of each line.Quote from: Dias de verano on December 10, 2008, 11:38:32 AM
Quote from: Jacob on December 10, 2008, 09:22:10 AM
My way was the quickest fix, but never mind.

Never mind indeed! His problem was a space at the beginning of each line. Your "solution" is for a space at the end of each line.

As I realized at 11 o'clock last night, sorry.


Discussion

No Comment Found