By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Text file parsing in batch files

watertraveller
P: 4
Hi. I'm new to batch files, and relatively new to the Windows command line in general.

I'm making a batch file for the Windows XP command line. I want to examine, for each line of a text file, what the first few characters are. I want to count up how many lines started with one set of characters, how many started with another, etc. And I want to output that count into a different text file.

I know how to read in the text and output it to a new file, but I don't know how to check just the first few characters. I also don't know how to store the count in a variable in the batch file. (Do batch files even have variables? They must, right?)

Thank you for your time; I appreciate it.
Sep 17 '08 #1
Share this Question
Share on Google+
4 Replies


Nepomuk
Expert 2.5K+
P: 3,112
Hi watertraveller! Welcome to bytes.com!

It's great to have you here!

When you post, please always keep to the Posting Guidelines and when you post code, please post it in [code] ... [/code] tags.

About your question: Yes, you can set variables in batch files. For example:
Expand|Select|Wrap|Line Numbers
  1. set countA=0
  2. set /a countA+=1
  3. echo There were %countA% a's in that text.
will return the current value of the variable countA (which is 1).

I'm not sure how to actually extract the first character from a line, but that should certainly help a bit.

Otherwise, I'll just wish you the best and hope you enjoy being part of bytes.com!

Greetings,
Nepomuk

PS.: I've started a thread in the Feedback Forum to find out, why that signature wont show up.
Sep 18 '08 #2

100+
P: 283
one command that might help you is ' FOR ' , just type ' for /? ' to see the syntax

I don't really know if you can do exactly what you want from a batch file / dos and I have not tried to do anything similar but I suspect that you might have to resort to using VBScript to achieve this.

also a little more complicated but you might want to look at Microsoft's Powershell as it is VERY powerful once you work out how to use it :)
Sep 18 '08 #3

watertraveller
P: 4
Thanks, I'll take a look at vbscript and, if I have to, PowerShell.
Sep 23 '08 #4

100+
P: 283
post back if you have any problems and if I can find time I will see if I can work out some vbs code.
Sep 24 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.