I want something like $ grep -rin "foo bar" but with the option to display the file location visually like tree but with the results trimmed so that only the recursive directories are displayed. It would be better if it was structured so that the directory listing is only displayed once with every location displayed within the directory tree. Like if I want to know every location where a method is called, I can quickly parse that on the command line. Anyone know of a tool that does this already or a simple technique, or do I need to script it myself?

  • Botzo@lemmy.world
    link
    fedilink
    arrow-up
    13
    ·
    edit-2
    12 days ago

    grep -l will get you just the filenames

    tree --fromfile will read from stdin just fine

    So: grep -ril "foo bar" . | tree --fromfile -a should do the trick.

    Edit: removed -n from the grep incantation per below conversation.

      • Botzo@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        12 days ago

        Good point! No use for a line number when you’re explicitly dumping file names. And if it did work, would likely break the pipe to tree.

        I lazily copied the original and just added -l.