Skip to content

Herramientas Bash

Busqueda de texto en archivos
#!/bin/bash
usage() {
echo "Usage: $0 <search_text> [-H|-l]"
echo " -H: Show file names and matching lines (default)"
echo " -l: Show only file names"
exit 1
}
# Set default grep option
grep_option="-H"
# Check if at least one argument is provided
if [ $# -eq 0 ]; then
usage
fi
# Set the search text
search_text="$1"
shift
# Check for optional parameter
if [ "$1" = "-l" ]; then
grep_option="-l"
elif [ "$1" = "-H" ]; then
grep_option="-H"
fi
# Perform the search
find . -type f \( -not -path "*/node_modules/*" -and -not -path "*/.git/*" \) -exec grep $grep_option "$search_text" {} +