Findme

From Attie's Wiki
(Difference between revisions)
Jump to: navigation, search
m (Created page with 'This is a nice little script that will recursively search the current directory for a string The <code>search_string</code> and <code>file_mask</code> use regex... you have been…')
 
m
Line 16: Line 16:
 
     if [ ! "`echo "$f" | grep -E -- "$MYMASK"`" = "" ]; then
 
     if [ ! "`echo "$f" | grep -E -- "$MYMASK"`" = "" ]; then
 
       if [ ! "`cat "$f" | grep -i -E -- "$1"`" = ""  ] ; then
 
       if [ ! "`cat "$f" | grep -i -E -- "$1"`" = ""  ] ; then
         if [ "`file -b "$f" | grep -- "^ASCII"`" ]; then
+
         echo -e "\0033[93m$f\0033[0m"
          echo -e "\0033[93m$f\0033[0m"
+
        grep -inTE -C2 --color=always -- "$1" "$f"
          grep -inTE -C2 --color=always -- "$1" "$f"
+
        echo -en "\0033[94m"
          echo -en "\0033[94m"
+
        echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
          echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
        echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
          echo -n "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
        echo -e "\0033[0m"
          echo -e "\0033[0m"
+
        fi;
+
 
       fi;
 
       fi;
 
     fi;
 
     fi;

Revision as of 14:06, 27 September 2011

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
        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;
  done;
fi
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox