View Full Version : Findstr question


Jon Smith
I need to run a find or findstr command on a dir with text files, and I need
the lines reterned that get matches, but I DON'T want the file names as
well, just the strings from the files. is there anyway to do that? I've
been pulling my hair out on this one.

the output I'm getting from FIND is

****************
FIND "BASEURL" *.url

---------- SLASHDOT.URL
BASEURL=http://slashdot.org/
---------- THE REGISTER USA.URL
BASEURL=http://www.theregus.com/
****************

and on findstr I'm getting

****************
Slashdot.url:BASEURL=http://slashdot.org/
The Register USA.url:BASEURL=http://www.theregus.com/
****************

but what I want is
****************
http://slashdot.org/
http://www.theregus.com/
****************

thanks



Jon Smith
or rathe what I want is

****************
BASEURL=http://slashdot.org/
BASEURL=http://www.theregus.com/
****************

"Jon Smith" wrote in message
news:uVqy3zjEEHA.3864@TK2MSFTNGP12.phx.gbl...
> I need to run a find or findstr command on a dir with text files, and I
need
> the lines reterned that get matches, but I DON'T want the file names as
> well, just the strings from the files. is there anyway to do that? I've
> been pulling my hair out on this one.
>
> the output I'm getting from FIND is
>
> ****************
> FIND "BASEURL" *.url
>
> ---------- SLASHDOT.URL
> BASEURL=http://slashdot.org/
> ---------- THE REGISTER USA.URL
> BASEURL=http://www.theregus.com/
> ****************
>
> and on findstr I'm getting
>
> ****************
> Slashdot.url:BASEURL=http://slashdot.org/
> The Register USA.url:BASEURL=http://www.theregus.com/
> ****************
>
> but what I want is
> ****************
> http://slashdot.org/
> http://www.theregus.com/
> ****************
>
> thanks
>
>



Phil Robyn [MVP]
Jon Smith wrote:
[color=blue]
> I need to run a find or findstr command on a dir with text files, and I need
> the lines reterned that get matches, but I DON'T want the file names as
> well, just the strings from the files. is there anyway to do that? I've
> been pulling my hair out on this one.
>
> the output I'm getting from FIND is
>
> ****************
> FIND "BASEURL" *.url
>
> ---------- SLASHDOT.URL
> BASEURL=http://slashdot.org/
> ---------- THE REGISTER USA.URL
> BASEURL=http://www.theregus.com/
> ****************
>
> and on findstr I'm getting
>
> ****************
> Slashdot.url:BASEURL=http://slashdot.org/
> The Register USA.url:BASEURL=http://www.theregus.com/
> ****************
>
> but what I want is
> ****************
> http://slashdot.org/
> http://www.theregus.com/
> ****************
>
> thanks
>
>[/color]

From the CMD prompt:

for /f "tokens=2 delims==" %a in ('findstr "BASEURL" *.url') do @echo %a

In a batch file:

for /f "tokens=2 delims==" %%a in ('findstr "BASEURL" *.url') do echo %%a

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

foxidrive
On Thu, 25 Mar 2004 00:44:11 -0700, Jon Smith wrote:
[color=blue]
> I need to run a find or findstr command on a dir with text files, and I need
> the lines reterned that get matches, but I DON'T want the file names as
> well, just the strings from the files. is there anyway to do that? I've
> been pulling my hair out on this one.
>
> the output I'm getting from FIND is
>
> ****************
> FIND "BASEURL" *.url
>
> ---------- SLASHDOT.URL
> BASEURL=http://slashdot.org/
> ---------- THE REGISTER USA.URL
> BASEURL=http://www.theregus.com/
> ****************[/color]

Just to add to Phil's solution, you can use find as a filter.

From the command line

for %a in (*.htm) do find "BASEURL" <%a


double the %'s for a batch file.
[color=blue]
> thanks[/color]

np

Phil Robyn
Jon Smith wrote:
[color=blue]
> or rathe what I want is
>
> ****************
> BASEURL=http://slashdot.org/
> BASEURL=http://www.theregus.com/
> ****************[/color]

for /f "tokens=1,2,* delims=:" %a in ('findstr "BASEURL" *.url') do @echo %c
[color=blue]
>
> "Jon Smith" wrote in message
> news:uVqy3zjEEHA.3864@TK2MSFTNGP12.phx.gbl...
>[color=green]
>>I need to run a find or findstr command on a dir with text files, and I[/color]
>
> need
>[color=green]
>>the lines reterned that get matches, but I DON'T want the file names as
>>well, just the strings from the files. is there anyway to do that? I've
>>been pulling my hair out on this one.
>>
>>the output I'm getting from FIND is
>>
>>****************
>>FIND "BASEURL" *.url
>>
>>---------- SLASHDOT.URL
>>BASEURL=http://slashdot.org/
>>---------- THE REGISTER USA.URL
>>BASEURL=http://www.theregus.com/
>>****************
>>
>>and on findstr I'm getting
>>
>>****************
>>Slashdot.url:BASEURL=http://slashdot.org/
>>The Register USA.url:BASEURL=http://www.theregus.com/
>>****************
>>
>>but what I want is
>>****************
>>http://slashdot.org/
>>http://www.theregus.com/
>>****************
>>
>>thanks
>>
>>[/color]
>
>
>[/color]


--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Jon Smith
thank you all...

"Jon Smith" wrote in message
news:uVqy3zjEEHA.3864@TK2MSFTNGP12.phx.gbl...
> I need to run a find or findstr command on a dir with text files, and I
need
> the lines reterned that get matches, but I DON'T want the file names as
> well, just the strings from the files. is there anyway to do that? I've
> been pulling my hair out on this one.
>
> the output I'm getting from FIND is
>
> ****************
> FIND "BASEURL" *.url
>
> ---------- SLASHDOT.URL
> BASEURL=http://slashdot.org/
> ---------- THE REGISTER USA.URL
> BASEURL=http://www.theregus.com/
> ****************
>
> and on findstr I'm getting
>
> ****************
> Slashdot.url:BASEURL=http://slashdot.org/
> The Register USA.url:BASEURL=http://www.theregus.com/
> ****************
>
> but what I want is
> ****************
> http://slashdot.org/
> http://www.theregus.com/
> ****************
>
> thanks
>
>



Jon Smith
sorry for another question, but I'm trying to pipe this to a file and I'm
doing

for /f "tokens=2 delims==" %a in ('findstr /s "BASEURL"
"%homepath%/favorites\*.url"') do @echo %a > c:\bookmark.txt

and it's not working but it's echoing fine, is there something elce i need
to put in there?

Thanks

"Phil Robyn [MVP]" wrote in message
news:ut5Y36jEEHA.3016@TK2MSFTNGP11.phx.gbl...[color=blue]
> Jon Smith wrote:
>[color=green]
> > I need to run a find or findstr command on a dir with text files, and I[/color][/color]
need[color=blue][color=green]
> > the lines reterned that get matches, but I DON'T want the file names as
> > well, just the strings from the files. is there anyway to do that? I've
> > been pulling my hair out on this one.
> >
> > the output I'm getting from FIND is
> >
> > ****************
> > FIND "BASEURL" *.url
> >
> > ---------- SLASHDOT.URL
> > BASEURL=http://slashdot.org/
> > ---------- THE REGISTER USA.URL
> > BASEURL=http://www.theregus.com/
> > ****************
> >
> > and on findstr I'm getting
> >
> > ****************
> > Slashdot.url:BASEURL=http://slashdot.org/
> > The Register USA.url:BASEURL=http://www.theregus.com/
> > ****************
> >
> > but what I want is
> > ****************
> > http://slashdot.org/
> > http://www.theregus.com/
> > ****************
> >
> > thanks
> >
> >[/color]
>
> From the CMD prompt:
>
> for /f "tokens=2 delims==" %a in ('findstr "BASEURL" *.url') do @echo[/color]
%a[color=blue]
>
> In a batch file:
>
> for /f "tokens=2 delims==" %%a in ('findstr "BASEURL" *.url') do echo[/color]
%%a[color=blue]
>
> --
> Phil Robyn
> Univ. of California, Berkeley
>
> u n z i p m y a d d r e s s t o s e n d e - m a i l[/color]



Matthias Tacke
"Jon Smith" wrote:
[color=blue]
>sorry for another question, but I'm trying to pipe this to a file and I'm
>doing
>
>for /f "tokens=2 delims==" %a in ('findstr /s "BASEURL"
>"%homepath%/favorites\*.url"') do @echo %a > c:\bookmark.txt
>
>and it's not working but it's echoing fine, is there something elce i need
>to put in there?
>[/color]
Hello Jon,

your posting will be better readable if you omit unrelevant parts and
continue at the end.

The single > creates the file anew every time. Delete the file at start
and then append to it with the doubled >> redirection.

HTH
--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm

Paul R. Sadowski
"Jon Smith" wrote in message
news:ud2EofoEEHA.3064@tk2msftngp13.phx.gbl...[color=blue]
> sorry for another question, but I'm trying to pipe this to a file and I'm
> doing
>
> for /f "tokens=2 delims==" %a in ('findstr /s "BASEURL"
> "%homepath%/favorites\*.url"') do @echo %a > c:\bookmark.txt[/color]

This should work:
for /f "tokens=2 delims==" %a in ('findstr /s "BASEURL"
"%homepath%/favorites\*.url"') do @echo %a >> c:\bookmark.txt

double > (">>") to append entries to the file. With a single > you are
overwriting the file for each new entry so that in the end only the last
entry would appear in the file.




Jon Smith
or rathe what I want is

****************
BASEURL=http://slashdot.org/
BASEURL=http://www.theregus.com/
****************

"Jon Smith" wrote in message
news:uVqy3zjEEHA.3864@TK2MSFTNGP12.phx.gbl...
> I need to run a find or findstr command on a dir with text files, and I
need
> the lines reterned that get matches, but I DON'T want the file names as
> well, just the strings from the files. is there anyway to do that? I've
> been pulling my hair out on this one.
>
> the output I'm getting from FIND is
>
> ****************
> FIND "BASEURL" *.url
>
> ---------- SLASHDOT.URL
> BASEURL=http://slashdot.org/
> ---------- THE REGISTER USA.URL
> BASEURL=http://www.theregus.com/
> ****************
>
> and on findstr I'm getting
>
> ****************
> Slashdot.url:BASEURL=http://slashdot.org/
> The Register USA.url:BASEURL=http://www.theregus.com/
> ****************
>
> but what I want is
> ****************
> http://slashdot.org/
> http://www.theregus.com/
> ****************
>
> thanks
>
>



Phil Robyn [MVP]
Jon Smith wrote:
[color=blue]
> I need to run a find or findstr command on a dir with text files, and I need
> the lines reterned that get matches, but I DON'T want the file names as
> well, just the strings from the files. is there anyway to do that? I've
> been pulling my hair out on this one.
>
> the output I'm getting from FIND is
>
> ****************
> FIND "BASEURL" *.url
>
> ---------- SLASHDOT.URL
> BASEURL=http://slashdot.org/
> ---------- THE REGISTER USA.URL
> BASEURL=http://www.theregus.com/
> ****************
>
> and on findstr I'm getting
>
> ****************
> Slashdot.url:BASEURL=http://slashdot.org/
> The Register USA.url:BASEURL=http://www.theregus.com/
> ****************
>
> but what I want is
> ****************
> http://slashdot.org/
> http://www.theregus.com/
> ****************
>
> thanks
>
>[/color]

From the CMD prompt:

for /f "tokens=2 delims==" %a in ('findstr "BASEURL" *.url') do @echo %a

In a batch file:

for /f "tokens=2 delims==" %%a in ('findstr "BASEURL" *.url') do echo %%a

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

foxidrive
On Thu, 25 Mar 2004 00:44:11 -0700, Jon Smith wrote:
[color=blue]
> I need to run a find or findstr command on a dir with text files, and I need
> the lines reterned that get matches, but I DON'T want the file names as
> well, just the strings from the files. is there anyway to do that? I've
> been pulling my hair out on this one.
>
> the output I'm getting from FIND is
>
> ****************
> FIND "BASEURL" *.url
>
> ---------- SLASHDOT.URL
> BASEURL=http://slashdot.org/
> ---------- THE REGISTER USA.URL
> BASEURL=http://www.theregus.com/
> ****************[/color]

Just to add to Phil's solution, you can use find as a filter.

From the command line

for %a in (*.htm) do find "BASEURL" <%a


double the %'s for a batch file.
[color=blue]
> thanks[/color]

np

Phil Robyn
Jon Smith wrote:
[color=blue]
> or rathe what I want is
>
> ****************
> BASEURL=http://slashdot.org/
> BASEURL=http://www.theregus.com/
> ****************[/color]

for /f "tokens=1,2,* delims=:" %a in ('findstr "BASEURL" *.url') do @echo %c
[color=blue]
>
> "Jon Smith" wrote in message
> news:uVqy3zjEEHA.3864@TK2MSFTNGP12.phx.gbl...
>[color=green]
>>I need to run a find or findstr command on a dir with text files, and I[/color]
>
> need
>[color=green]
>>the lines reterned that get matches, but I DON'T want the file names as
>>well, just the strings from the files. is there anyway to do that? I've
>>been pulling my hair out on this one.
>>
>>the output I'm getting from FIND is
>>
>>****************
>>FIND "BASEURL" *.url
>>
>>---------- SLASHDOT.URL
>>BASEURL=http://slashdot.org/
>>---------- THE REGISTER USA.URL
>>BASEURL=http://www.theregus.com/
>>****************
>>
>>and on findstr I'm getting
>>
>>****************
>>Slashdot.url:BASEURL=http://slashdot.org/
>>The Register USA.url:BASEURL=http://www.theregus.com/
>>****************
>>
>>but what I want is
>>****************
>>http://slashdot.org/
>>http://www.theregus.com/
>>****************
>>
>>thanks
>>
>>[/color]
>
>
>[/color]


--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Jon Smith
thank you all...

"Jon Smith" wrote in message
news:uVqy3zjEEHA.3864@TK2MSFTNGP12.phx.gbl...
> I need to run a find or findstr command on a dir with text files, and I
need
> the lines reterned that get matches, but I DON'T want the file names as
> well, just the strings from the files. is there anyway to do that? I've
> been pulling my hair out on this one.
>
> the output I'm getting from FIND is
>
> ****************
> FIND "BASEURL" *.url
>
> ---------- SLASHDOT.URL
> BASEURL=http://slashdot.org/
> ---------- THE REGISTER USA.URL
> BASEURL=http://www.theregus.com/
> ****************
>
> and on findstr I'm getting
>
> ****************
> Slashdot.url:BASEURL=http://slashdot.org/
> The Register USA.url:BASEURL=http://www.theregus.com/
> ****************
>
> but what I want is
> ****************
> http://slashdot.org/
> http://www.theregus.com/
> ****************
>
> thanks
>
>



Jon Smith
sorry for another question, but I'm trying to pipe this to a file and I'm
doing

for /f "tokens=2 delims==" %a in ('findstr /s "BASEURL"
"%homepath%/favorites\*.url"') do @echo %a > c:\bookmark.txt

and it's not working but it's echoing fine, is there something elce i need
to put in there?

Thanks

"Phil Robyn [MVP]" wrote in message
news:ut5Y36jEEHA.3016@TK2MSFTNGP11.phx.gbl...[color=blue]
> Jon Smith wrote:
>[color=green]
> > I need to run a find or findstr command on a dir with text files, and I[/color][/color]
need[color=blue][color=green]
> > the lines reterned that get matches, but I DON'T want the file names as
> > well, just the strings from the files. is there anyway to do that? I've
> > been pulling my hair out on this one.
> >
> > the output I'm getting from FIND is
> >
> > ****************
> > FIND "BASEURL" *.url
> >
> > ---------- SLASHDOT.URL
> > BASEURL=http://slashdot.org/
> > ---------- THE REGISTER USA.URL
> > BASEURL=http://www.theregus.com/
> > ****************
> >
> > and on findstr I'm getting
> >
> > ****************
> > Slashdot.url:BASEURL=http://slashdot.org/
> > The Register USA.url:BASEURL=http://www.theregus.com/
> > ****************
> >
> > but what I want is
> > ****************
> > http://slashdot.org/
> > http://www.theregus.com/
> > ****************
> >
> > thanks
> >
> >[/color]
>
> From the CMD prompt:
>
> for /f "tokens=2 delims==" %a in ('findstr "BASEURL" *.url') do @echo[/color]
%a[color=blue]
>
> In a batch file:
>
> for /f "tokens=2 delims==" %%a in ('findstr "BASEURL" *.url') do echo[/color]
%%a[color=blue]
>
> --
> Phil Robyn
> Univ. of California, Berkeley
>
> u n z i p m y a d d r e s s t o s e n d e - m a i l[/color]



Matthias Tacke
"Jon Smith" wrote:
[color=blue]
>sorry for another question, but I'm trying to pipe this to a file and I'm
>doing
>
>for /f "tokens=2 delims==" %a in ('findstr /s "BASEURL"
>"%homepath%/favorites\*.url"') do @echo %a > c:\bookmark.txt
>
>and it's not working but it's echoing fine, is there something elce i need
>to put in there?
>[/color]
Hello Jon,

your posting will be better readable if you omit unrelevant parts and
continue at the end.

The single > creates the file anew every time. Delete the file at start
and then append to it with the doubled >> redirection.

HTH
--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm

Paul R. Sadowski
"Jon Smith" wrote in message
news:ud2EofoEEHA.3064@tk2msftngp13.phx.gbl...[color=blue]
> sorry for another question, but I'm trying to pipe this to a file and I'm
> doing
>
> for /f "tokens=2 delims==" %a in ('findstr /s "BASEURL"
> "%homepath%/favorites\*.url"') do @echo %a > c:\bookmark.txt[/color]

This should work:
for /f "tokens=2 delims==" %a in ('findstr /s "BASEURL"
"%homepath%/favorites\*.url"') do @echo %a >> c:\bookmark.txt

double > (">>") to append entries to the file. With a single > you are
overwriting the file for each new entry so that in the end only the last
entry would appear in the file.