Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

delete blank lines & csv from a text file

Posted on 2003-12-02
4
Medium Priority
?
3,937 Views
Last Modified: 2007-12-19
Hello,

How do I:

1) delete all blank lines from my input text file
2) My data is in 2 columns separated by space. Like:
    Data1          Data2
   
    Data3          Data4

    I want to make it a comma separated file. That is delete the spaces between the data and make it delimited by comma.

The output will be like:

Data1,Data2
Data3,Data4
(Blank lines deleted and a csv file)

Thanks

0
Comment
Question by:kamur
[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
4 Comments
 
LVL 16

Accepted Solution

by:
_nn_ earned 500 total points
ID: 9859568
Directly from the command line :

for /f "tokens=1-2" %a in (source.txt) do (>>source.csv echo %a,%b)

In a batch :

for /f "tokens=1-2" %%a in (source.txt) do (>>source.csv echo %%a,%%b)
0
 
LVL 5

Expert Comment

by:brianadkins
ID: 9859611

input.txt
--------------8<--------------
Data1 Data2

Data3 Data4

--------------8<--------------



convert.bat
--------------8<--------------
@echo off
set INFILE=%1
set OUTFILE=%INFILE:.txt=.csv%
if exist %OUTFILE% del %OUTFILE%
for /f "tokens=1,2" %%a in ('findstr /v /r "^$" %INFILE%') do (
>> %OUTFILE% echo %%a,%%b
)
--------------8<--------------

-Brian Adkins

0
 
LVL 5

Expert Comment

by:brianadkins
ID: 9859622
_nn_,

oops...  you beat me to it.

-Brian
0
 

Author Comment

by:kamur
ID: 9859655
Too good...Fantastic.

Thanks _nn_ and Brian !! I guess I have to give the points to _nn_!

Regards
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 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