Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 17th, 2008, 11:17 PM
watertraveller's Avatar
Newbie
 
Join Date: Sep 2008
Posts: 4
Default Text file parsing in batch files

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.

Last edited by watertraveller; September 17th, 2008 at 11:23 PM. Reason: I can't get my signature to show up.
Reply
  #2  
Old September 18th, 2008, 09:19 AM
Nepomuk's Avatar
Moderator
 
Join Date: Aug 2007
Location: Germany
Age: 21
Posts: 1,817
Default

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:
Code:
set countA=0
set /a countA+=1
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.
Reply
  #3  
Old September 18th, 2008, 05:36 PM
Familiar Sight
 
Join Date: Mar 2008
Posts: 244
Default

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 :)
Reply
  #4  
Old September 23rd, 2008, 07:49 PM
watertraveller's Avatar
Newbie
 
Join Date: Sep 2008
Posts: 4
Default

Thanks, I'll take a look at vbscript and, if I have to, PowerShell.
Reply
  #5  
Old September 24th, 2008, 04:37 PM
Familiar Sight
 
Join Date: Mar 2008
Posts: 244
Default

post back if you have any problems and if I can find time I will see if I can work out some vbs code.
Reply
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles