简体   繁体   English

猫的无效选项3

[英]Invalid option 3 for cat

When I am trying to run the below Script it says invalid option 3 for cat..Whats the problem? 当我尝试运行以下脚本时,它说cat。的选项3无效。是什么问题? I am tried to use index file which specifies which file is ham and which is spam...to read the files and train spamfilter 我试图使用索引文件来指定哪个文件是火腿,哪个是垃圾邮件...以读取文件并训练spamfilter

#!bin/bash
DirBogoDict=$1
BogoFilter=/home/gunna/Downloads/bogofilter-1.2.4/src/bogofilter
x=0
for i in 'cat index | fgrep spam | head -300 | awk -F "/" '{print$2"/"$3}''

do
     x=$((x+1)) ; echo $x


cat  /home/gunna/Downloads/db-6.1.19.NC/build_unix/ceas08-1/$i| $BogoFilter -d $DirBogoDict -M -k 1024 -s

done

for i in 'cat index | fgrep ham | head -300 | awk -F "/" '{print$2"/"$3}''


do
     x=$((x+1)) ; echo $x


cat   /home/gunna/Downloads/db-6.1.19.NC/build_unix/ceas08-1/$i | $BogoFilter -d $DirBogoDict -M -k 1024 -n

done

This part 这部分

 'cat index | fgrep spam | head -300 | awk -F "/" '{print$2"/"$3}''

needs to be in back-ticks, not single quotes 需要使用反引号,而不是单引号

`cat index | fgrep spam | head -300 | awk -F "/" '{print$2"/"$3}'`

And you could probably simplify it a little with 您可能会用

for i in `fgrep spam index | head -300 | awk "/" '{print$2"/"$3}'`

Kdopen has explained the error you got , here is the improved code for similar for-loop function. Kdopen解释了您遇到的错误,这是类似的for循环函数的改进代码。

DirBogoDict=$1
BogoFilter=/home/gunna/Downloads/bogofilter-1.2.4/src/bogofilter

awk '/spam/&&++myctr<=300{print $2 FS $3}' FS="/" index |while read i
do
    cat  /home/gunna/Downloads/db-6.1.19.NC/build_unix/ceas08-1/"$i"| $BogoFilter -d ${DirBogoDict} -M -k 1024 -s
done

awk '/ham/&&++myctr<=300{print $2 FS $3}' FS="/" index |while read i
do
    cat  /home/gunna/Downloads/db-6.1.19.NC/build_unix/ceas08-1/"$i"| $BogoFilter -d ${DirBogoDict} -M -k 1024 -s
done

Also look at your file names , since cat is giving an error and an option is invalid. 另外,请查看您的文件名,因为cat给出了错误,并且选项无效。 To demonstrate this, Let say you have a file a name -3error 为了说明这一点,假设您有一个名为-3error的文件

executing the following command 执行以下命令

cat -3error

will gave 将给

cat: invalid option -- '3'

cat therefore is thinking the "-" is followed by one of its command line arguments. 因此,cat认为“-”后面是其命令行参数之一。 As a result you probably get an invalid option error. 结果,您可能会收到无效的选项错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM