2013-03-18 95 views
0

嗨,我正在努力解决这个简单的程序。我无法将文本文件中的值传递给变量。 我被困在此:value=$(sed -n "${line}p" rpt1.txt|awk {$3}将文本传递给KSH中的变量。不工作

O/P:

1.sh[15]: test: argument expected 

CODE:

wc `find /arbor/custom/gur/fold1`|grep -vi "total"| tee rpt1.txt 
total1=`wc -l rpt1.txt` 
wc `find /arbor/custom/gur/fold2`|grep -vi "total"| tee rpt2.txt 
total2=`wc -l rpt2.txt` 
line=1 
if [ $line -le $total1 ] 
then 
value=$(sed -n "${line}p" rpt1.txt|awk {$3}) 
if [ $value -eq 512 ]; 
then 
sed -n "${line}p" rpt1.txt|awk '{print $4}'| tee direc.txt 
fi 
line =$line+1 
else 
echo "loop over" 
fi 
+0

您的代码不太可读。我有一种感觉,有些东西被stackoverflow解释为标记,这使得很难说出什么是问题,什么不是。无论如何,我的猜测是你在awk程序中缺少引号。 – Eric 2013-03-18 15:40:14

+0

@Eric是对的,你需要'awk'{$ 3}''。 – squiguy 2013-03-18 15:45:14

+0

@Eric非常感谢。 Squiguy你的建议工作! – greatvedas 2013-03-18 16:13:47

回答

0

不应该有在$ 3前在犯罪嫌疑人行打印?

+0

。我纠正了。它的工作!非常感谢。 – greatvedas 2013-03-18 16:14:32