J'écris un script bash pour rechercher un motif dans un fichier en utilisant GREP. Je suis désemparé pour pourquoi cela ne fonctionne pas. Ceci est le programmeScript Bash utilisant Grep pour rechercher un motif dans un fichier
echo "Enter file name...";
read fname;
echo "Enter the search pattern";
read pattern
if [ -f $fname ]; then
result=`grep -i '$pattern' $fname`
echo $result;
fi
Ou est-il une approche différente pour le faire?
Merci
(contenu du fichier)
Welcome to UNIX
The shell is a command programming language that provides an interface to the UNIX operating system.
The shell can modify the environment in which commands run.
Simple UNIX commands consist of one or more words separated by blanks.
Most commands produce output on the standard output that is initially connected to the terminal. This output may be sent to a file by writing.
The standard output of one UNIX command may be connected to the standard input of another UNIX Command by writing the `pipe' operator, indicated by |
(modèle)
`UNIX` or `unix`
grep doit être redirigé par un "afaik", faisant ainsi 'ls -l | grep '^ d''par exemple retournera tous les répertoires dans l'emplacement actuel ... – deostroll
grep fonctionnera à partir d'une liste de noms de fichiers, ou un caractère générique. Il n'a pas besoin d'être canalisé. – Curtis
Votre motif inclut-il des caractères qui doivent être échappés? –