Re: Recursion with grep?

From: Kirk Strauser (kirk_at_strauser.com)
Date: 11/14/03

  • Next message: Sunil Sunder Raj: "Re: Postfix and SASL2 authentication"
    To: freebsd-questions@freebsd.org
    Date: Thu, 13 Nov 2003 23:46:19 -0600
    
    
    

    At 2003-11-14T03:42:18Z, Francisco J Reyes <fran@natserv.net> writes:

    > I think I am going to research what would it take for someone to fix grep
    > and pay them.

    Grep works perfectly in that respect, thanks - it's your understanding
    that's a bit askew. Say you're in a directory with 'file1.c', 'file2.c',
    'file3.c', etc. When you type:

        grep -r 'string' *.c

    your shell (*not* grep!) is expanding your command line to:

        grep -r 'string' file1.c file2.c file3.c

    Now, grep's man page says this:

           -r, --recursive
                  Read all files under each directory, recursively; this is equiv-
                  alent to the -d recurse option.

    None of the arguments you specified at the command line are directories -
    they're all files. What would you say is the proper behavior for recursing
    into a file?

    grep did exactly what you asked it to; your request was not what you thought
    it was, but grep had no way of knowing.

    > How do think we would want grep to work?
    >
    > Do we want something like:
    > grep -r <string> *.c

    No. We want to learn the proper usage of our tools. Take a look at the
    "find | grep" examples elsewhere in the thread.

    -- 
    Kirk Strauser
    "94 outdated ports on the box,
     94 outdated ports.
     Portupgrade one, an hour 'til done,
     82 outdated ports on the box."
    
    



  • Next message: Sunil Sunder Raj: "Re: Postfix and SASL2 authentication"

    Relevant Pages

    • Re: MacTeX 2007 and documentation
      ... may be the most useful command available when doing searches at the ... will find every file on your system that has the text "memoir" on it, ... If locate generates 30 lines of text, where each line is a file, grep ... I need a Unix guru to chat to for half an hour or so to put me straight. ...
      (comp.text.tex)
    • Re: piping multiple selections to mv or cp and exclusion
      ... pipe to shell to execute each command statement ... Unix is indeed lifelong learning :-) ... and the regexp. ... back into the grep statement. ...
      (comp.unix.shell)
    • Re: MacTeX 2007 and documentation
      ... means you need expertise in your host operating system as well. ... locate memoir | grep pdf ... I'm not someone who lives at the command line, ...
      (comp.text.tex)
    • Re: Program to scan directories
      ... Is there a UNIX command which scans directories and execute any other ... the regex you specify here is /not/ given to grep to ... entries (files and subdirectories). ... tell grep to recurse through the kpathsea directory (the *.h regex ...
      (comp.unix.programmer)
    • Re: Using the grep command to filter
      ... I am a college student currently enrolled in a Unix class. ... that ubuntu Ubuntu UBUNTU ubunTU whatever in them. ... grep ubuntu /etc/* of course. ... Now look at the output of that grep command will give you all the ...
      (comp.unix.shell)