Verybad

Поиск файлов по тексту

Jan 11th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #!/bin/bash
  2. cmd="find -type f -print "
  3. set_color_cmd="set_color"
  4. if [ $2 ]; then cmd="$cmd -name \"$2\""; fi
  5. color="green"
  6. if [ $3 ]; then color=$3; fi
  7.  
  8. is_colored=1
  9. hh=$(which "$set_color_cmd")
  10. if [ $? -ne 0 ]; then is_colored=''; fi
  11.  
  12. $cmd | while read f; do
  13. cnt=$(grep -c "$1" "$f")
  14. if [ $cnt -gt 0 ]; then
  15. if [ $is_colored ]; then "$set_color_cmd" "$color"; fi
  16. echo "$f"
  17. if [ $is_colored ]; then "$set_color_cmd" normal; fi
  18. grep -n "$1" "$f"
  19. fi
  20. done
Advertisement
Add Comment
Please, Sign In to add comment