Solved

DOS Findstr Command

Posted on 2009-07-06
5
1,532 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

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

11 Experts available now in Live!

Get 1:1 Help Now