Solved

Looking for a Windows Batch program to remove blank rows from a csv file

Posted on 2016-09-19
4
28 Views
Last Modified: 2016-09-19
I have a csv file generated by a Crystal Reports Export where I need to remove the blank rows generated by the Export within Crystal. I am looking for a Windows batch program that can be executed at a command line to do that. The blank rows are strings of commas.

The csv file opened in a text editor looks like below (actual file has many more columns)...

"Header1","Header2","Header3"
"A1","B1","C1"
"A2","B2","C2"
,,,
"A3","B3","C3"
,,,
,,,
"A4","B4","C4"


I need the blank rows removed to generate...

"Header1","Header2","Header3"
"A1","B1","C1"
"A2","B2","C2"
"A3","B3","C3"
"A4","B4","C4"
0
Comment
Question by:gbucal01
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
AnthonyHamon earned 500 total points
ID: 41805222
You can do this with a single line .cmd file as follows:
findstr /R /V "^,*$" inputfile.txt >outputfile.txt

Open in new window


Change inputfile.txt to the full path of the file generated by Crystal Reports and change outputfile.txt to the full path of the file to create that has the spurious lines removed.

In this .cmd file, the findstr command is used to identify any lines that are just made up of commas and exclude these from the output.  I am assuming that there are no trailing spaces on the lines that contain only commas.
0
 

Author Comment

by:gbucal01
ID: 41805241
This worked. Thank You! So the /v is to skip when the string is found and the "^,*$"  identifies the string of commas?
0
 
LVL 4

Expert Comment

by:AnthonyHamon
ID: 41805261
You are correct: /V is to output only lines that do not match the search string and "^,*$" is a regular expression which defines a string of commas.  ^ means match at the beginning of the line ,* means match 1 or more commas and $ means match at the end of the line.
0
 

Author Closing Comment

by:gbucal01
ID: 41805268
Thank You for your help!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now