简体   繁体   中英

Invalid option 3 for cat

When I am trying to run the below Script it says invalid option 3 for cat..Whats the problem? I am tried to use index file which specifies which file is ham and which is spam...to read the files and train 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.

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. To demonstrate this, Let say you have a file a name -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. As a result you probably get an invalid option error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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