Blank Lines in Text file

I am outputting a text file using bcp to a customer and my output writes a blank line at the end of the file.  The customer cannot accept any blank lines at the beginning or end of file.  The bcp command is reading from a ## table and I have checked to see if there are any blank rows in the table.  There are no blank rows.

Does anyone know of a way to make sure no blank lines appear at the end of a file.

This is my bcp statement

SELECT @bcpCmdStr = 'bcp "Select * From ##tmpGLBalExportTab " queryout "' + @bcpOutFile + '" -S ' + @sqlSrv + ' -c -T -t "\t"'

Thanks in advance
sherbug1015Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nemws1Database AdministratorCommented:
Are there any other blank lines that you want to *keep*?  Found this solution online that removes all blanks line via the CMD window.

type test.txt | findstr /v "^$" >> ntext.txt

Open in new window

0
sherbug1015Author Commented:
nemws1 - This does not work.
0
nemws1Database AdministratorCommented:
You need to have the proper line endings for it to work.  Try this instead:
type test.txt | findstr "." >> ntest.txt

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

sherbug1015Author Commented:
Is this solution supposed to remove the blank line at the end of a text file?   If so, it does not work.  What it comes down to is removing the CRLF from the last line of the file.  Since all the lines of the file have a CRLF at the end, how would I distinguish between on CRLF and the other.
0
sherbug1015Author Commented:
I was not able to use your solution, but I think I have to award the points anyway.
0
nemws1Database AdministratorCommented:
You do not have to assign points.  I don't want points I haven't earned.  With that said, do you have access to PowerShell?  If so, this one liner works in my tests and works regardless of line endings:

(gc testfile.txt) | ? {$_.trim() -ne "" } | set-content testfile2.txt

If this was UNIX, the command is simply and easy.  Unfortunately, Windows doesn't come with the many text file manipulation tools that UNIX systems do.
0
nemws1Database AdministratorCommented:
If you don't have powershell, try this guy:

http://www.xoc.de/trim.php

You'll want the '/E' flag to remove empty lines from a file.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.