Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how to get the Count of string in file  (Read 42700 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: how to get the Count of string in file
« Reply #45 on: August 13, 2010, 01:47:06 PM »
Code: [Select]
@echo off
 >substringcount.vbs echo  substring = wscript.arguments(0)
>>substringcount.vbs echo longstring = wscript.arguments(1)
>>substringcount.vbs echo    Subslen = Len(Substring)
>>substringcount.vbs echo    longlen = Len(longstring)
>>substringcount.vbs echo   Subcount = 0
>>substringcount.vbs echo   Substart = InStr ( longstring, Substring )
>>substringcount.vbs echo If Substart ^> 0 Then
>>substringcount.vbs echo Do
>>substringcount.vbs echo Subcount = Subcount + 1
>>substringcount.vbs echo longstring = Mid( longstring, ( Substart + Subslen ) )
>>substringcount.vbs echo Substart = InStr ( longstring,Substring )
>>substringcount.vbs echo If Substart = 0 Then Exit Do
>>substringcount.vbs echo Loop
>>substringcount.vbs echo End If
>>substringcount.vbs echo wscript.echo Subcount

set mainstring="arun*America*MSC~INS*dfffs*Sdfsd*sdfsd~ssfsd*sdfsd~INS*dfffs*sdfsdf*sdfs~"
set substring="INS*"

for /f "delims=" %%C in ('cscript //nologo substringcount.vbs %substring% %mainstring%') do set count=%%C

echo Found string %substring% %count% times in string %mainstring%


Code: [Select]
S:\>test.bat
Found string "INS*" 2 times in string "arun*America*MSC~INS*dfffs*Sdfsd*sdfsd~ssfsd*sdfsd~INS*dfffs*sdfsdf*sdfs~"

victoria



    Beginner

    Thanked: 1
    Re: how to get the Count of string in file
    « Reply #46 on: August 13, 2010, 03:18:30 PM »
    Code: [Select]
    @echo off
     

    Code: [Select]
    S:>test.bat
    Found string \"INS*\" 2 times in \"string \"arun*America*MSC~INS*dfffs*Sdfsd*sdfsd~ssfsd*sdfsd~INS*dfffs*sdfsdf*sdfs~\"




    cntstr.bat  INS*  st813.txt

    rem @echo  off

    sed s/INS*/INS**n/g st813.txt   | findstr INS*  | find  /c /v  **
    count=2

    echo Display string
    Display string


    type st813.txt
    arun*America*MSC~INS*dfffs*dfsd*sdfsd~ssfsd*sdfsd~INS*dfffs*sdfsdf*sdfs~
    * replace * with backslash
    ** replace with double quotes

    ( see above )
    Have a Nice Day

    vishuvishal



      Beginner
    • Thanked: 3
      Re: how to get the Count of string in file
      « Reply #47 on: August 13, 2010, 03:42:15 PM »

      sed s/the/the*n/g id.txt  |  findstr the   | find /c /v **
      count=10

      * replace * with backslash symbol
      **  replace ** with two double quotes

      sed for windows is an easy download

      sed  means stream editor


      Thanks for all the research work. I appreciate it.

      You are really hard working.





      I am thinking myself to be a beginner.
      I think I must keep my mouth
       :P :P :P :-X :-X :-X :P :P :P

      Thanks Victoria.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: how to get the Count of string in file
      « Reply #48 on: August 13, 2010, 03:45:20 PM »
      vishuvishal: just out of curiousity, where are you from?  :)
      I was trying to dereference Null Pointers before it was cool.

      Salmon Trout

      • Guest
      Re: how to get the Count of string in file
      « Reply #49 on: August 13, 2010, 04:11:33 PM »
      Quote
      Found string \"INS*\" 2 times in \"string \"arun*America*MSC~INS*dfffs*Sdfsd*sdfsd~ssfsd*sdfsd~INS*dfffs*sdfsdf*sdfs~\"

      Where are those back slashes coming from?

      Salmon Trout

      • Guest
      Re: how to get the Count of string in file
      « Reply #50 on: August 13, 2010, 04:12:12 PM »
      vishuvishal: just out of curiousity, where are you from?  :)

      Not too far from Bill's trailer, I daresay.

      vishuvishal



        Beginner
      • Thanked: 3
        Re: how to get the Count of string in file
        « Reply #51 on: August 13, 2010, 04:30:30 PM »
        Quote
        Re: how to get the Count of string in file
        « Reply #50 on: Today at 04:12:12 PM »    Reply with quote
        Quote from: BC_Programmer on Today at 03:45:20 PM
        vishuvishal: just out of curiousity, where are you from?  Smiley

        Not too far from Bill's trailer, I daresay.

        I am far from there.

        I am somewhere from eastern side.
        I hope you will hate me for this.

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: how to get the Count of string in file
        « Reply #52 on: August 13, 2010, 05:10:05 PM »
        I am far from there.
        And yet in the same time zone?

        Quote
        I am somewhere from eastern side.
        Eastern side of what?
        Quote
        I hope you will hate me for this.

        um, ok.

        I was trying to dereference Null Pointers before it was cool.

        victoria



          Beginner

          Thanked: 1
          Re: how to get the Count of string in file
          « Reply #53 on: August 13, 2010, 05:14:09 PM »
          Where are those back slashes coming from?


          I connect to Computerhope.com through a Proxy Server

          The following is a guess about the orgin of random blackslashes:
          The Editor at the Proxy Server posts my post here at Computerhope.com?
          The Editor at the Proxy Server inserts the random backslashes?

          Or  the staff here at computerhope.com sets their editor to insert random backslashes?

          I do not know how to correct the problem.

          Thanks for your help.


          Have a Nice Day

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: how to get the Count of string in file
          « Reply #54 on: August 13, 2010, 05:38:40 PM »
          I do not know how to correct the problem.

          Go away. That'll fix it.
          I was trying to dereference Null Pointers before it was cool.

          victoria



            Beginner

            Thanked: 1
            Re: how to get the Count of string in file
            « Reply #55 on: August 13, 2010, 06:15:37 PM »
            Go away. That will  fix it.

            What have I done to hurt anything?

            Why should I leave?
            Have a Nice Day

            victoria



              Beginner

              Thanked: 1
              Re: how to get the Count of string in file
              « Reply #56 on: August 13, 2010, 06:34:20 PM »

              Thanks for all the research work. I appreciate it.

              You are really hard working.


              I enjoy trying to answer questions.
              I believe sed is a very useful tool for many problems.
              Sed was written by AT&T many years ago for the  Unix Operating System.
              Sed is now used with many operating systems.

              p.s. Ignore the negative comments by some of the other posters.
              The people making the negative comments have a ton of good  information when they
              choose to help.
              Why do they have a need to insult people who came to Computerhope looking for help?

              Good Luck
              Have a Nice Day

              victoria



                Beginner

                Thanked: 1
                Re: how to get the Count of string in file
                « Reply #57 on: August 13, 2010, 08:45:51 PM »

                Thanks for all the research work. I appreciate it.



                Have a Nice Day

                Salmon Trout

                • Guest
                Re: how to get the Count of string in file
                « Reply #58 on: August 14, 2010, 12:50:29 AM »
                And yet in the same time zone?
                Eastern side of what?

                Billrich's trailer? Billrich's head more like.


                Salmon Trout

                • Guest
                Re: how to get the Count of string in file
                « Reply #59 on: August 14, 2010, 01:08:04 AM »
                Why should I leave?

                Because you were banned before and forbidden to return.