当前位置: 技术问答>linux和unix
帮我看个 shell方面的问题,我菜的很
来源: 互联网 发布时间:2015-08-02
本文导语: #!/bin/sh if [ $# -ne 1 ] then echo "Usage: `basename $0` [DATE(YYYYMM)]" echo "Example: `basename $0` 200201" echo "" exit 0 fi EXC=$1 if [ -f ./jsqd_13697797855_${EXC}.dat ] then ...
#!/bin/sh
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` [DATE(YYYYMM)]"
echo "Example: `basename $0` 200201"
echo ""
exit 0
fi
EXC=$1
if [ -f ./jsqd_13697797855_${EXC}.dat ]
then
echo "exist jsqd_13697797855_${EXC}.dat, delete it first."
exit
fi
zcat /home/js/jdata/qds/wjjsh/${EXC}/nor_file/ZH*.dat.Z | awk '{
zj = substr($0,1,20);
bj = substr($0,21,20);
rqsj = substr($0,57,14);
thsc = substr($0,71,6);
jfsc = substr($0,77,6);
if (zj~/^0756/) {
if (bj~/^13697797855/ )
printf "%-20s:%-20s:%-8s:%-6s:%-6s:%-6sn",substr(zj,5,7),substr(bj,1,20),substr(rqsj,1,8),substr(rqsj,9,6),thsc,jfsc;
}
else if (substr(zj,1,1)!='1' && substr(zj,1,1)!='0') {
if (bj~/^13697797855/ )
printf "%-20s:%-20s:%-8s:%-6s:%-6s:%-6sn",substr(zj,1,7),substr(bj,1,20),substr(rqsj,1,8),substr(rqsj,9,6),thsc,jfsc;
}
}' > ./jsqd_13697797855_${EXC}.dat
fi
echo "formatting wjjs qd,Please wait ..."
Wc -l ./jsqd_13697797855_${EXC}.dat
echo "format done!"
程序一运行,老提示:
format_13697797855.sh: line 34: syntax error near unexpected token `fi'
format_13697797855.sh: line 34: `fi'
到底是那里问题?
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` [DATE(YYYYMM)]"
echo "Example: `basename $0` 200201"
echo ""
exit 0
fi
EXC=$1
if [ -f ./jsqd_13697797855_${EXC}.dat ]
then
echo "exist jsqd_13697797855_${EXC}.dat, delete it first."
exit
fi
zcat /home/js/jdata/qds/wjjsh/${EXC}/nor_file/ZH*.dat.Z | awk '{
zj = substr($0,1,20);
bj = substr($0,21,20);
rqsj = substr($0,57,14);
thsc = substr($0,71,6);
jfsc = substr($0,77,6);
if (zj~/^0756/) {
if (bj~/^13697797855/ )
printf "%-20s:%-20s:%-8s:%-6s:%-6s:%-6sn",substr(zj,5,7),substr(bj,1,20),substr(rqsj,1,8),substr(rqsj,9,6),thsc,jfsc;
}
else if (substr(zj,1,1)!='1' && substr(zj,1,1)!='0') {
if (bj~/^13697797855/ )
printf "%-20s:%-20s:%-8s:%-6s:%-6s:%-6sn",substr(zj,1,7),substr(bj,1,20),substr(rqsj,1,8),substr(rqsj,9,6),thsc,jfsc;
}
}' > ./jsqd_13697797855_${EXC}.dat
fi
echo "formatting wjjs qd,Please wait ..."
Wc -l ./jsqd_13697797855_${EXC}.dat
echo "format done!"
程序一运行,老提示:
format_13697797855.sh: line 34: syntax error near unexpected token `fi'
format_13697797855.sh: line 34: `fi'
到底是那里问题?
|
一开始还好,但是从if (zj~/^0756/)开始所有的if你都需要加then,还有嵌套if时要注意fi的匹配。
|
}' > ./jsqd_13697797855_${EXC}.dat
fi
echo "formatting wjjs qd,Please wait ..."
wc -l ./jsqd_13697797855_${EXC}.dat
echo "format done!"
把上面出现的fi去掉就可以了。
fi
echo "formatting wjjs qd,Please wait ..."
wc -l ./jsqd_13697797855_${EXC}.dat
echo "format done!"
把上面出现的fi去掉就可以了。
|
看来是我看错了