Solved

delete blank lines & csv from a text file

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now