我正在编写一个bash脚本来使用GREP在文件中搜索模式。我无能为力,为什么它不工作。这是程序Bash脚本使用Grep来搜索文件中的模式
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
还是有不同的方法来做到这一点?
感谢
(文件的内容)
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 |
(模式)
`UNIX` or `unix`
grep应该是管道afaik,所以'ls -l |例如,grep'^ d''将返回当前位置中的所有目录... – deostroll 2010-06-16 11:42:28
grep将从文件名列表或通配符开始工作。它不必管道。 – Curtis 2010-06-16 11:43:57
您的模式是否包含需要转义的字符? – 2010-06-16 11:58:21