About Finding Batch Labels using FINDSTR

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

About Finding Batch Labels using FINDSTR

#1 Post by Meerkat » 20 Dec 2015 10:57

Hi again guys!

Assuming the quirky rules from http://www.dostips.com/forum/viewtopic.php?f=3&t=3803 are not in my batch file (Only whitespaces are present), how can I detect batch labels using FINDSTR?

For instance, (Sample.bat)

Code: Select all

::Intro comments
::Blablabla
::Yeah!!!
::Blablabla

@echo off
   ::Comment again
   goto :main

   ::Some codes here...

   :main
   ::Some code here
   echo This is some piece of code...

   :thisisalabel
   ::this is a comment...
pause
exit /b

From my young intuition, I tried to use this FINDSTR command:

Code: Select all

>findstr /r ":[^:][^:]*" Sample.bat

I expect that only :main and :thisisalabel will appear, but the output became:

Code: Select all

::Some comments
::Blablabla
::Yeah
::Blablabla
        ::Comment again
        goto :main
        ::Some codes here...
        :main
        ::Some code here
        :thisisalabel
        ::this is a comment...

What is wrong with my FINDSTR? :| Thanks a lot guys! :D

Meerkat

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: About Finding Batch Labels using FINDSTR

#2 Post by Aacini » 20 Dec 2015 13:33

Code: Select all

> findstr /R /C:"^ *:[^:]" Sample.bat
   :main
   :thisisalabel
 

Antonio

Post Reply