Solved

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

Posted on 2016-09-19
4
63 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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