Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Blank Lines in Text file

Posted on 2014-08-13
7
Medium Priority
?
544 Views
Last Modified: 2014-08-15
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
0
Comment
Question by:sherbug1015
  • 4
  • 3
7 Comments
 
LVL 23

Expert Comment

by:nemws1
ID: 40259666
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
 

Author Comment

by:sherbug1015
ID: 40259692
nemws1 - This does not work.
0
 
LVL 23

Accepted Solution

by:
nemws1 earned 1500 total points
ID: 40259809
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:sherbug1015
ID: 40260976
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
 

Author Closing Comment

by:sherbug1015
ID: 40262814
I was not able to use your solution, but I think I have to award the points anyway.
0
 
LVL 23

Expert Comment

by:nemws1
ID: 40263101
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
 
LVL 23

Expert Comment

by:nemws1
ID: 40263120
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

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question