Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell Can';t grep文件是否正确_Shell_Grep - Fatal编程技术网

Shell Can';t grep文件是否正确

Shell Can';t grep文件是否正确,shell,grep,Shell,Grep,我有一个语法非常简单的文件: cat /tmp/test ARCH=""prtconf -b | awk '/^name:/ {print $2}' 我试着让它变绿: cat /tmp/test | grep "prtconf -b | awk '/^name:/ {print $2" ARCH=""prtconf -b | awk '/^name:/ {print $2}' 让我们把grep字符串加长一点,在末尾添加}: cat /tmp/test | grep "prtconf -b

我有一个语法非常简单的文件:

cat /tmp/test

ARCH=""prtconf -b | awk '/^name:/ {print $2}'
我试着让它变绿:

cat /tmp/test | grep "prtconf -b | awk '/^name:/ {print $2"

ARCH=""prtconf -b | awk '/^name:/ {print $2}'
让我们把grep字符串加长一点,在末尾添加}:

cat /tmp/test | grep "prtconf -b | awk '/^name:/ {print $2"}
什么也没找到

为什么在行尾添加}时grep停止工作


OS是Solaris 10U11

$2
引用命令行参数,因此这里它将替换模式中的空白字符。所以你需要像
\$

cat /tmp/test | grep "prtconf -b | awk '/^name:/ {print \$2}"

没有在您的模式中添加
,因为它匹配实际模式为
prtconf-b | awk'/^name:/{print
,用于输入。但是如果您在模式中添加
,它将尝试匹配
prtconf-b | awk'/^name:/{print}
(它不在您的文件中,因此不会显示输出)

阅读有关猫的无用使用奖。更少的代码意味着更少的出错机会。开始使用
grep'srchTarg'文件| otherstuff
作为标准表单。还要注意编辑框左上角的
{}
工具。选择您的代码并单击
{}
,以获得更好的问题格式。祝你好运。@sluge,你试过我的答案了吗??