Solved

DOS Findstr Command

Posted on 2009-07-06
5
1,541 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
  • 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Selective Copy and overwrite 7 60
command line argument to replace text in a file 4 62
How to Skip in FOR command if a Directory does not exist. 6 87
how to count files? 4 31
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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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