hervasiop12345

bustr_mej

Oct 12th, 2011
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.74 KB | None | 0 0
  1. #!/bin/bash
  2. #Author:jMa
  3. #Description: Lista los ficheros del árbol a partir de un directorio que contienen una cadena
  4. if [ \( $# -lt 2 \) ] || [ \( $# -gt 2 \) ]
  5. then
  6.    echo "Error. Sintaxis: bustr_mej cadena directorio(con permisos r y x)"
  7.    exit 1
  8. elif [ \( -d "$2" \) ] && [ \( -r "$2" \) ] && [ \( -x "$2" \) ]
  9. then
  10.    cd $2
  11.    if [ `grep -lr $1 * | wc -l` -gt "1" ]
  12.    then
  13.       echo "La cadena $1 se ha encontrado en los siguientes ficheros:"
  14.       grep -lr $1 * > dirs
  15.       while read line
  16.       do
  17.          echo -e "\t-$line"
  18.       done < ./dirs
  19.    else
  20.       echo "No se ha encontrado ninguna coincidencia"
  21.    fi
  22.    exit 0
  23. else
  24.    echo "Error. Sintaxis: bustr_mej cadena directorio(con permisos r y x)"
  25.    exit 1
  26. fi
Advertisement
Add Comment
Please, Sign In to add comment