Solved

delete blank lines & csv from a text file

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 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