Solved

delete blank lines & csv from a text file

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
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…

856 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