Solved

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

Posted on 2016-09-19
4
40 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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 …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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