Solved

DOS Findstr Command

Posted on 2009-07-06
5
1,558 Views
Last Modified: 2012-05-07
I have a huge file containing statistics of certain operation. Each record has 3 columns with each column value seperated by a comma. I need to display only the columns with numerical values and ignore the columns which are either empty or have special charecters or string literals using DOS commands. Please help.
56787,"",""
375678,"dfyh","jhmfgy"

Open in new window

0
Comment
Question by:Kishore_chintalpati
[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
  • 3
  • 2
5 Comments
 

Author Comment

by:Kishore_chintalpati
ID: 24789432
Urgent.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24789546
If all yo want to do is display data from the first column, then the following batch file will do the job.

Copy and paste the following code into Notepad and save it as PROCNUM.BAT in the same folder as your CSV file. Fire up a DOS session and enter the command:

   PROCNUM


@echo off
for /f "tokens=1-3 delims=," %%a in ('type columns.txt') do (
   echo %%a
)
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24789628
If there is a possibility of numerical data appearing in any column, then this will display the numerical data in column format. (The 'SET COLUMNS=' line is followed by 12 spaces).

@echo off
set column=            
for /f "tokens=1-3 delims=," %%a in ('type columns.txt') do (
   echo %%a|findstr "[^0123456789]">NUL
   if errorlevel 1 echo %%a
   echo %%b|findstr "[^0123456789]">NUL
   if errorlevel 1 echo %column%%%b
   echo %%c|findstr "[^0123456789]">NUL
   if errorlevel 1 %column%%column%%%c
)
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 300 total points
ID: 24789690
Sorry for the misleading labels in the previous code. Oh, by the way, Don't forget to change the name "CSVFILE.TXT" in the FOR-line to the name of your 'HUGE file'...

Here's a slightly better version of the previous code.

@echo off
set spaces=            
for /f "tokens=1-3 delims=," %%a in ('type CSVFILE.TXT') do (
   echo %%a|findstr "[^0123456789]">NUL
   if errorlevel 1 echo %%a
   echo %%b|findstr "[^0123456789]">NUL
   if errorlevel 1 echo %spaces%%%b
   echo %%c|findstr "[^0123456789]">NUL
   if errorlevel 1 %spaces%%spaces%%%c
)


0
 

Author Closing Comment

by:Kishore_chintalpati
ID: 31600365
Thank you brother... You rock !!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

724 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