Hi Experts,
I have some tough time with findstr for few days.
My requirement is to search for a particular string (from the output of net share command) which either ends with a space or a end of line.
For ex:
C:\>net share
Share name Resource Remark
-------------------------------------------------------------------------------
IPC$ Remote IPC
D$ D:\ Default share
C$ C:\ Default share
ADMIN$ C:\windows Remote Admin
ab C:\ab
abc C:\abc
abcdddafdfdd C:\abcdddafdfdd
abdafdafdsfdfadfdfdafdafdsfdfsafdsfdfdfdfdafdafdafdfdafdfdafdafdfdf
C:\abdafdafdsfdfadfdfdafdafdsfdfsafdsfdfdfdfdafdafdafdfdafdfdafdafdfdf
Here I wanted to search for the line which contains only "C:\ab".
However the below findstr command gives all matches with C:\ab.
C:\>FOR /F "tokens=*" %I IN ('net share ^|findstr /C:"C:\ab"' ) DO @echo %I
ab C:\ab
abc C:\abc
abcdddafdfdd C:\abcdddafdfdd
C:\abdafdafdsfdfadfdfdafdafdsfdfsafdsfdfdfdfdafdafdafdfdafdfdafdafdfdf
My requirement is to find the string "C:\ab" which either ends with a space or a end-of the line character.
Appreciate any help on this.
Thanks
Sambasiva
Findstr: search for strings ends with space or a newline
Moderator: DosItHelp
Re: Findstr: search for strings ends with space or a newline
If you need to specify a space or line end in the findstr search string, then just append a space or a line end (see: help findstr):
penpen
Code: Select all
findstr /R /C:"C:\ab " /C:"C:\ab$"
penpen
Re: Findstr: search for strings ends with space or a newline
PenPen,
Thanks for the reply.
It didnt work in my case.
Below command didn't yield any output
C:\>net share |findstr /R /C:"C:\ab " /C:"C:\ab$"
C:\>
Thanks for the reply.
It didnt work in my case.
Code: Select all
C:\>net share
Share name Resource Remark
-------------------------------------------------------------------------------
IPC$ Remote IPC
D$ D:\ Default share
C$ C:\ Default share
ADMIN$ C:\windows Remote Admin
ab C:\ab
abc C:\abc
abcdddafdfdd C:\abcdddafdfdd
abdafdafdsfdfadfdfdafdafdsfdfsafdsfdfdfdfdafdafdafdfdafdfdafdafdfdf
C:\abdafdafdsfdfadfdfdafdafdsfdfsafdsfdfdfdfdafdafdafdfdafdfdafdafdfdf
The command completed successfully.
Below command didn't yield any output

C:\>net share |findstr /R /C:"C:\ab " /C:"C:\ab$"
C:\>
Re: Findstr: search for strings ends with space or a newline
Sorry, just a flaw with the '\' (why? see: "findstr /?"), use:
penpen
Code: Select all
net share |findstr /R /C:"C:\\ab " /C:"C:\\ab$"
penpen
Re: Findstr: search for strings ends with space or a newline
It's working..Thanks a lot PenPen