Solved

DOS Findstr Command

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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