ksh:意外令牌“完成”附近的语法错误

时间:2016-11-08 03:00:17

标签: unix awk ksh

我正在尝试编写一个脚本,将符合特定条件的行输出到新的.txt文件中,尝试合并unix和awk

谷歌搜索,但一直收到此错误:意外令牌“完成”附近的语法错误

Filename="bishan"
file="659.A"
while IFS= read line
do
   cat $Filename.txt | awk '{ otherSubNo = substr($0,73,100);gsub(/    
   /,"",otherSubNo); if(length(otherSubNo)>8){ print "Subscriber Number is
   ",": ",substr($0,1,20)," Other Subscriber Number is ", " :    
   ",substr($0,73,100) }}'| wc -l >> $Filename.txt 
done <"$file"

659.A的例子如下: 这是659.a文件的第一行:

6581264562 201611050021000000002239442239460000000019010000010081866368

        00C0525016104677451     100C 0                                  0000

0111000 000000000000000000006598540021 01010000000000659619778001010000 000000659854000300000000000000000000 004700001

请帮助,我一直在谷歌上搜索但无济于事

1 个答案:

答案 0 :(得分:1)

我能够通过在记事本(windows)中键入脚本并在cygwin中测试它来重现指定的错误,尽管只是近似接近。

script.sh:

while read myline
do
echo $myline
done

在ksh:

~> /usr/bin/ksh ./script.sh
: not found
./script.sh[7]: syntax error: 'done' unexpected

在bash中:

~> /usr/bin/bash ./script.sh
./script.sh: line 2: $'\r': command not found
./script.sh: line 6: syntax error near unexpected token `done'
./script.sh: line 6: `done'

上述错误(至少在我的情况下)是因为CRLF字符。当我将代码复制粘贴到cygwin时,CRLF变为LF(以及丢失的所有不可见控制字符),从而使错误消失。