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
Solved

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

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

792 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