how to fetch exact string from a text file

February 4, 2010 at 08:59:50
Specs: Windows 2003
Hi All,

here is me requirement.

I have one text file and I need to get exact specified string from that file

C:>type small.txt | find "small2"

small2

small22

small20

C:>type small.txt small2

small22

small20

C:>type small.txt | find "small2" small2

small22

small20

C:\

Here it is giving all the words instead of only "small2"

Plz help me in this.. it's urgent

Thanks in advance


See More: how to fetch exact string from a text file

Report •


#1
February 4, 2010 at 09:07:12
ok.. I got the solution

C:\>findstr "\<small20\>" small.txt
small20
C:\>


Report •

#2
February 4, 2010 at 09:24:39
What do you want it to do once you found it? Do you want it to just say found then try this....

@echo off
set Found=Not Found
For /F "tokens=* delims= " %%A in (%2) do (
  if %%A==%1 set Found=Found
  echo %%A %1 %Found%
)
echo %Found%

The syntax assuming you save this script in MyFind.bat, would be...

c:\> myFind small2 small.txt

If you tell me what you want to do once you find the text in the file like print the location of the text or what, I can modify the code to help you more.

Test Results...

With small.txt containing...

small2
big 2
small22
big 1
small20

c:\> myFind small2 small.txt
Found

With small.txt containing...

small23
big 2
small22
big 1
small20

c:\> myFind small2 small.txt
Not Found


Report •

Related Solutions


Ask Question