Solved

DOS Findstr Command

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

26 Experts available now in Live!

Get 1:1 Help Now