Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Space in Output File  (Read 3682 times)

0 Members and 1 Guest are viewing this topic.

zero2here

    Topic Starter


    Starter

    Space in Output File
    « on: December 09, 2008, 09:52:11 AM »
    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 tmpFile

    devcom



      Apprentice

      Thanked: 37
      Re: Space in Output File
      « Reply #1 on: December 09, 2008, 10:46:44 AM »
      you 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 ?
      Download: Choice.exe

      zero2here

        Topic Starter


        Starter

        Re: Space in Output File
        « Reply #2 on: December 09, 2008, 11:01:46 AM »
        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



        devcom



          Apprentice

          Thanked: 37
          Re: Space in Output File
          « Reply #3 on: December 09, 2008, 11:25:00 AM »
          is this your completed script ? post all becouse i cant see any errors in this one
          Download: Choice.exe

          Jacob



            Hopeful

            Thanked: 1
            • Experience: Expert
            • OS: Windows XP
            Re: Space in Output File
            « Reply #4 on: December 09, 2008, 11:53:55 AM »
            Instead 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  ;)
            « Last Edit: December 09, 2008, 12:07:15 PM by Jacob »

            zero2here

              Topic Starter


              Starter

              Re: Space in Output File
              « Reply #5 on: December 10, 2008, 08:59:31 AM »
              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! 

              Jacob



                Hopeful

                Thanked: 1
                • Experience: Expert
                • OS: Windows XP
                Re: Space in Output File
                « Reply #6 on: December 10, 2008, 09:22:10 AM »
                My way was the quickest fix, but never mind.

                Dias de verano

                • Guest
                Re: Space in Output File
                « Reply #7 on: December 10, 2008, 11:38:32 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.

                Jacob



                  Hopeful

                  Thanked: 1
                  • Experience: Expert
                  • OS: Windows XP
                  Re: Space in Output File
                  « Reply #8 on: December 11, 2008, 07:04:29 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.