Solved

delete blank lines & csv from a text file

Posted on 2003-12-02
4
3,930 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 125 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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