编译unix脚本代码时,我在第43行遇到语法错误。此代码用于搜索文本文件夹,并匹配input.txt中的任何单词。 代码仍然没有完成,但
#!/bin/bash
findkeyword () {
file="$1"
keyword="$2"
value="$3"
int count = 0
cat $file | awk '{
while read line
do
for (ii=1;ii<=NF;ii++) {
if ($ii == $keyword)
count++
fi
}
done
}'
echo "Profile: " $file
scorefile $value $count
scorefile () {
value="$1"
count="$2"
echo "Score: " $value*$count
}
cat input.txt | awk '{
while read line
do
keyword=$1
value=$2
for xx in `ls submissions/*`
do
filename=$xx
findkeyword $filename $keyword $value
done
done
}'
答案 0 :(得分:0)
#!/bin/bash
findkeyword () {
file="$1"
keyword="$2"
value="$3"
int count = 0
while read line; do
for word in $line; do
if [[ $word = $keyword ]]; then
$((count++))
fi
done
done <$file
echo "Profile: " $file
scorefile $value $count
} # missing closing brace here
scorefile () {
value="$1"
count="$2"
echo "Score: " $(($value*$count)) # Math evaluation broken
}
while read line
do
keyword=$1
value=$2
for xx in `ls submissions/*`
do
filename=$xx
findkeyword $filename $keyword $value
done
done<input.txt