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,你试过我的答案了吗??