How do I do this im terrible at Batch???

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mai
Posts: 3
Joined: 12 Aug 2007 20:29

How do I do this im terrible at Batch???

#1 Post by Mai » 12 Aug 2007 20:37

How do I get the number of s in file.txt?

Full File:
echo/%f|findstr /b /c:"%ref_no%" >nul
if not errorlevel 1 (
echo/%f%s >>file.txt
) else echo/%f >>file.txt
)
echo :: How many times you used s in file.txt
FindStr /B /C:s file.txt | Find /C "s"
ping -n 2 127.0.0.1>nul
echo :: Done.
ping -n 2 127.0.0.1>nul
pause

and in file.txt lets say u say
s
s
s

It should come up in batch like this.
echo :: How many times you used s in file.txt
3

3<<< ??Now how do I get this number in a .txt file from batch file??

I know how to do
echo/%f|findstr /b /c:"%ref_no%" >nul
if not errorlevel 1 (
echo/%f%s >>file.txt
) else echo/%f >>file.txt
)

It must have something to do with echo/%f%s >>file.txt But what? Maybe a Professional will help me.

Thank You
Jessica

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 13 Aug 2007 00:51

Mai,

Like this?

Code: Select all

type file.txt|find /c "s"

DOS IT HELP? :wink:

Mai
Posts: 3
Joined: 12 Aug 2007 20:29

#3 Post by Mai » 13 Aug 2007 02:01

Hi soeey again but um... it didnt help much that just shows how many s's are in the file.txt. How would I type file.txt|find /c "s" and get the number of "s" so i can save it in the file.txt from the batch file I made?

Example:
@echo off
echo/%f|findstr /b /c:"%ref_no%" >nul
if not errorlevel 1 (
echo/%f%s>>file.txt
) else echo/%f >>file.txt
)
type file.txt|find /c "s"
type file.txt|find /c "s">>%file.txt
pause
test.bat


Now next to the s in file.txt i want it to say how many s's were in file.txt.
From the example above I want it like this:
s 1
s 2
s 3
s 4
s 5

Instead of this
s
1
s
2
s
3
s
4
s
5
um.. If its impossible just tell me >.<

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#4 Post by DosItHelp » 13 Aug 2007 11:34

MAI,

You use some syntax that I'm not familiar with: "echo/%f"
What is %f? should it be %f% (one percent sign missing at the end)?

Well I think I get your point. How about this:

Code: Select all

set "FindIn=sourcefile.txt"
for /f %%N in ('" type "%FindIn%"|find /c "s" "') do set "cnt=%%N"
echo.%FindIn% %cnt%>>file.txt

What do you think?
Last edited by DosItHelp on 01 Sep 2007 23:13, edited 3 times in total.

Mai
Posts: 3
Joined: 12 Aug 2007 20:29

#5 Post by Mai » 14 Aug 2007 01:35

I tryed it but it dont do anything but say sourcefile.txt with echo off and pause added. That or I dont understand what u mean. Maybe you dont understand what i mean ? >.< copy paste the above one and look in file.txt.

I want it like this:
s 1
s 2
s 3
s 4
s 5

Instead of this
s
1
s
2
s
3
s
4
s

I was also wondering if its possible to make rainbow color (like color 1, color 2, color 3, color 4)in batch well still being able to do commands in a menu in batch. That would be a cool menu but I dont think its possible.

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#6 Post by DosItHelp » 01 Sep 2007 23:18

Mai,

Sorry the last line had a space missing.

Code: Select all

set "FindIn=sourcefile.txt"
for /f %%N in ('" type "%FindIn%"|find /c "s" "') do set "cnt=%%N"
echo.%FindIn% %cnt%
echo.%FindIn% %cnt% >>file.txt


This counts all lines in sourcefile.txt that have an 's' in it. The result appears in file.txt and on screen.

DosItHelp?

Post Reply