Page 1 of 1

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

Posted: 12 Aug 2007 20:37
by Mai
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

Posted: 13 Aug 2007 00:51
by DosItHelp
Mai,

Like this?

Code: Select all

type file.txt|find /c "s"

DOS IT HELP? :wink:

Posted: 13 Aug 2007 02:01
by Mai
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 >.<

Posted: 13 Aug 2007 11:34
by DosItHelp
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?

Posted: 14 Aug 2007 01:35
by Mai
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.

Posted: 01 Sep 2007 23:18
by DosItHelp
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?