Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

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

Posted on 2016-09-19
4
Medium Priority
?
120 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

647 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