Sto scrivendo uno script bash per cercare un pattern in un file usando GREP. Sono senza tracce per il motivo per cui non funziona. Questo è il programmaBash Script che utilizza Grep per cercare un pattern in un file
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
Oppure c'è un altro approccio per farlo?
Grazie
(il contenuto del file)
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 |
(modello)
`UNIX` or `unix`
grep deve essere collegato in pipe, quindi facendo 'ls -l | grep '^ d''per esempio restituirà tutte le directory nella posizione corrente ... – deostroll
grep funzionerà da un elenco di nomi di file o da un carattere jolly. Non deve essere convogliato. – Curtis
Il tuo pattern include caratteri che devono essere sottoposti a escape? –