Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Cleptography
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
-
Contact:
#1
Post
by Cleptography » 15 Jun 2011 01:38
How can I search through a text file like this and determine the integers?
Code: Select all
99201 22839 19283
19283 ABSJD 92839
00293 LSKDJ 90LSK
-
nitt
- Posts: 218
- Joined: 22 Apr 2011 02:43
#2
Post
by nitt » 15 Jun 2011 01:45
Cleptography wrote:How can I search through a text file like this and determine the integers?
Code: Select all
99201 22839 19283
19283 ABSJD 92839
00293 LSKDJ 90LSK
I do not understand what you mean by "determine". Do you want to like run a FOR loop through every character and if one is an integer then return true for that one loop or something? Or do you want to check an entire line, or the entire thing? Or do you want to count how many integers there are?
-
Cleptography
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
-
Contact:
#3
Post
by Cleptography » 15 Jun 2011 01:57
Just check each group of chars and determine if it is an integer, and if it is not print something that says ????? was not an integer.
This might make it easier.
So determine which of the above are integers.
Thanks nitt
-
orange_batch
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
-
Contact:
#4
Post
by orange_batch » 15 Jun 2011 03:41
Easy as pie.
Code: Select all
for /f "tokens=1" %%a in (textfile.txt) do set var=&set /a var+=1%%a 2>nul||echo:%%a is not an integer.
We prefix the 1 to prevent DOS from interpreting a number starting with 0 as an octal. It also prevents set /a from interpreting any %%a starting with a letter as a variable.
-
Cleptography
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
-
Contact:
#5
Post
by Cleptography » 15 Jun 2011 04:23
Good job orange
Code: Select all
for /f "Tokens=*" %%a in ('type %1') do (
if %%a NEQ +%%a echo\Line containing {%%a} in file %1 is NOT an integer.
)