1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need 'grep' equivalent

Discussion in 'Support' started by old4doser, Jul 20, 2010.

  1. old4doser

    Joined:
    Jul 15, 2010
    Messages:
    6
    Likes Received:
    0
    Yes, I have looked (in vain) for this in Help. I have the calluses to prove it. I’ve also searched most of the Internet 4DOS-related websites with no success.

    What is the TC version of the UNIX “grep”. Right now I’m using the ‘The Berkeley Utilities V2.0’ ‘grep’ like this to test for a string in a file

    type "%theMonFile%" |grep -s markit
    set exitcode=%_?

    That works fine, but there has to be an equivalent way to do it with TC commands, but I cannot find out how to do it.

    A more basic use of ‘grep’ is to find all lines in a text file that contain a certain string. I’d like to know how to do that too.

    Normally, I’d be happy with just knowing what is used to get these two file searches done like ‘grep’. But given the scant nature of the examples in Help, a few examples would be appreciated.

    Or, let me know what to search for and I can try to find something in the forums.

    Thanks
     
  2. ebbe

    Joined:
    Jun 2, 2008
    Messages:
    31
    Likes Received:
    0
    If you don't need wildcards and all the other bells and whistles that a real grep gives you, the good old 'find' command (from cmd.exe) might be the answer:

    Code:
    C:\
    which find
    find is an external : C:\Windows\system32\find.exe
    
    C:\
    cmd /k help find
    Searches for a text string in a file or files.
    
    FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
    
      /V         Displays all lines NOT containing the specified string.
      /C         Displays only the count of lines containing the string.
      /N         Displays line numbers with the displayed lines.
      /I         Ignores the case of characters when searching for the string.
      /OFF[LINE] Do not skip files with offline attribute set.
      "string"   Specifies the text string to find.
      [drive:][path]filename
                 Specifies a file or files to search.
    
    If a path is not specified, FIND searches the text typed at the prompt
    or piped from another command.
    Ebbe
     
  3. nikbackm

    Joined:
    May 30, 2008
    Messages:
    194
    Likes Received:
    1
    Did you try the internal FFIND command? It should be usable via pipes and such as well according to the help.

    "If you don't supply a file name, FFIND will read from standard input. (This allows you to pipe or redirect input to FFIND.)"

    HTH
     
  4. drrob1

    drrob1 Guest

    list allows regular expressions. Is this what you want, or are you=20
    looking for something like the linux find command?

    On 07/20/2010 02:21 AM, old4doser wrote:

     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,729
    Likes Received:
    80
    The internal TCC "FFIND" command searches files (text, binary, or regular
    expressions).


    FFIND /v /t"string" filename

    The LIST command can also search files if you'd rather have a visual
    display.

    Rex Conn
    JP Software
     
  6. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    638
    Likes Received:
    6
    4DOS has the FFIND command, which is also in TCC.

    Joe
     
  7. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    | What is the TC version of the UNIX grep. Right now Im using the The
    | Berkeley Utilities V2.0 grep like this to test for a string in a
    | file
    |
    | type "%theMonFile%" |grep -s markit
    | set exitcode=%_?
    |
    | That works fine, but there has to be an equivalent way to do it with
    | TC commands, but I cannot find out how to do it.

    I am not familiar with the Berkeley version of grep, so I don't know
    what the return code means. Here are some variant uses of the TCC version
    11.0 command FFIND.
    - List of files that have at least one match to a plain text string:
    ffind /b /t"string" fileset
    - List of files that have at least one match to a regular expression:
    ffind /b /e"regex" fileset

    | A more basic use of grep is to find all lines in a text file that
    | contain a certain string. Id like to know how to do that too.

    Look up the /c, /l and /v options of FFIND. The only thing FFIND cannot
    do is what some versions of grep provide, namely, to provide a single line
    report containing filename, linenumber, and matching line for each match.
    BTW, FFIND's output can be fed through a pipe to any other command (or
    batchfile or even external program) providing an emulation of the POSIX
    command "find".
    --
    HTH, Steve
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    On Tue, 20 Jul 2010 02:21:55 -0400, old4doser <>
    wrote:

    |Yes, I have looked (in vain) for this in Help. I have the calluses to prove it. I’ve also searched most of the Internet 4DOS-related websites with no success.
    |
    |What is the TC version of the UNIX “grep”. Right now I’m using the ‘The Berkeley Utilities V2.0’ ‘grep’ like this to test for a string in a file
    |
    |type "%theMonFile%" |grep -s markit
    |set exitcode=%_?
    |
    |That works fine, but there has to be an equivalent way to do it with TC commands, but I cannot find out how to do it.
    |
    |A more basic use of ‘grep’ is to find all lines in a text file that contain a certain string. I’d like to know how to do that too.
    |
    |Normally, I’d be happy with just knowing what is used to get these two file searches done like ‘grep’. But given the scant nature of the examples in Help, a few examples would be appreciated.
    |
    |Or, let me know what to search for and I can try to find something in the forums.
    |
    |Thanks

    There's Windows's TCC's FFIND and FINDSTR.EXE, neither of which do
    full-blown regular expressions. My 4UTILS plugin provides a GREPP
    command.
     
  9. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    FFIND does do regular expressions with the /E switch. Which part is
    missing? I.e. what can't you do?

    -Scott

    vefatica <> wrote on 07/20/2010 12:01:16 PM:


     
  10. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    638
    Likes Received:
    6
    For some advanced searching, you may want to look into;

    @REGEX
    @REGEXINDEX
    @REGEXSUB

    Mind you, this may be more that what you require.

    Joe
     
  11. old4doser

    Joined:
    Jul 15, 2010
    Messages:
    6
    Likes Received:
    0
    My thanks for all of the responses to my question about a TC equivalent to
    the UNIX "grep" command. The responses were enlightening and revealing. The
    suggestions included the TC "ffind" and "filefind", Windows "find" and
    "findstr", plus a plugin and a lot of talk about Regular Expressions.



    In the end, the answer is NO. To me it's unconscionable that there wouldn't
    be one, but that seems to be the case. I'm an old UNIX guy, and what grep
    does is what I want the way grep does it. Just give me an exit-code and a
    list of "result" lines to stdout.



    The solutions to both of my "grep" needs is the Windows "find". One uses the
    /c (count) switch and the other is bare. My searches are only on ASCII/text
    files without any Regex.



    1. Is this string in the file?



    for /f "tokens=2 delims=:" %%a in ('find /c "%string%" "%filename"') do set
    fstr=%%a



    The variable "fstr" has the count (or 0) with a leading space. In that form,
    the variable can be used in an "if" of "iff" to test it.



    2. Get all lines with this string in them.



    find "%string%" "%filename"



    There are also /V and /I for "get all without the string" and
    "case-insensitive", both basic in the UNIX "grep".



    Again, my thanks. I included my findings in hopes of contributing something
    back for all your time and efforts.



    George





    -----Original Message-----
    From: old4doser [mailto:]
    Sent: Monday, July 19, 2010 11:22 PM
    To: mcgraw01@comcast.net
    Subject: [Support-t-2174] Need 'grep' equivalent



    Yes, I have looked (in vain) for this in Help. I have the calluses to prove
    it. I've also searched most of the Internet 4DOS-related websites with no
    success.



    What is the TC version of the UNIX "grep". Right now I'm using the 'The
    Berkeley Utilities V2.0' 'grep' like this to test for a string in a file



    type "%theMonFile%" |grep -s markit

    set exitcode=%_?



    That works fine, but there has to be an equivalent way to do it with TC
    commands, but I cannot find out how to do it.



    A more basic use of 'grep' is to find all lines in a text file that contain
    a certain string. I'd like to know how to do that too.



    Normally, I'd be happy with just knowing what is used to get these two file
    searches done like 'grep'. But given the scant nature of the examples in
    Help, a few examples would be appreciated.



    Or, let me know what to search for and I can try to find something in the
    forums.



    Thanks
     
  12. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    You may find that the internal FFIND command has a lot more power to do
    what you ask than you are giving it credit for.

    [C:\Tools\Crypto32] ffind /u /v /t"Crypt" *.cpp
    75 lines in 1 file

    [C:\Tools\Crypto32] ffind /u /v /t"foo" *.cpp
    0 lines in 0 files

    set fstr=%@word[0,%@execstr[ffind /u /v /t"%string" %filename]]

    or

    function matches=`%@word[0,%@execstr[ffind /u /v /t"%1" %2]]`
    echo %@matches[Crypt,*.cpp]
    echo %@matches[`Certificate failed`,*.cpp]

    Remove the /U switch to get the equivilent of your #2.

    1) find all occurances of %string within %filename case insensitive
    ffind /v /t"%string" %filename

    2) find all occurances of %string within %filename case sensitive
    ffind /v /c /t"%string" %filename

    -Scott



    old4doser <> wrote on 07/21/2010 06:08:55 AM:


    to

    The

    wouldn't

    grep

    a

    the

    ASCII/text

    set

    form,

    something

    prove

    no

    contain

    file

    the

     
  13. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
  14. old4doser

    Joined:
    Jul 15, 2010
    Messages:
    6
    Likes Received:
    0
    It turns out that ffind will do everything I want a virtual-grep to do. I
    passed it over before because the format of its "count" output was more
    complex than that of Windows' "find", and "find" had a straightforward
    "results" output. Also, I got "find" to work in a short time, while ffind
    was a 'file-find' command by definition and I didn't want to spend hours
    struggling with the options and post-processing to get what I had from
    "find".

    But, Scott (aka samintz) showed me how to get the "exitcode" (count) and
    "results" lines from ffind. In doing that, he provided examples of
    "function", @word and @execstr showing me how they work in a context that I
    was familiar with.

    Thanks Scott.

    -----Original Message-----
    From: samintz [mailto:]
    Sent: Wednesday, July 21, 2010 7:36 AM
    To: mcgraw01@comcast.net
    Subject: RE: [Support-t-2174] Need 'grep' equivalent

    You may find that the internal FFIND command has a lot more power to do
    what you ask than you are giving it credit for.

    [C:\Tools\Crypto32] ffind /u /v /t"Crypt" *.cpp
    75 lines in 1 file

    [C:\Tools\Crypto32] ffind /u /v /t"foo" *.cpp
    0 lines in 0 files

    set fstr=%@word[0,%@execstr[ffind /u /v /t"%string" %filename]]

    or

    function matches=`%@word[0,%@execstr[ffind /u /v /t"%1" %2]]`
    echo %@matches[Crypt,*.cpp]
    echo %@matches[`Certificate failed`,*.cpp]

    Remove the /U switch to get the equivilent of your #2.

    1) find all occurances of %string within %filename case insensitive
    ffind /v /t"%string" %filename

    2) find all occurances of %string within %filename case sensitive
    ffind /v /c /t"%string" %filename

    -Scott
     

Share This Page