Findme

From Attie's Wiki
Revision as of 11:29, 27 September 2011 by Attie (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a nice little script that will recursively search the current directory for a string

The search_string and file_mask use regex... you have been warned :)

#!/bin/bash
if [ "$1" = "" ]; then
  echo "Usage: $0 <search_string> [file_mask]";
else
  if [ ! "$2" = "" ]; then
    MYMASK=$2
  else
    MYMASK=.
  fi
  find . -type f -not -path "*/.svn*" -printf "%p\n" | while read f; do
    if [ ! "`echo "$f" | grep -E -- "$MYMASK"`" = "" ]; then
      if [ ! "`cat "$f" | grep -i -E -- "$1"`" = ""  ] ; then
        if [ "`file -b "$f" | grep -- "^ASCII"`" ]; then
          echo -e "\0033[93m$f\0033[0m"
          grep -inTE -C2 --color=always -- "$1" "$f"
          echo -en "\0033[94m"
          echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
          echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
          echo -e "\0033[0m"
        fi;
      fi;
    fi;
  done;
fi
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox