Hi im trying to write a script with bash that accesses a site, with articles, looking for desired links end with numbers or chars,capital or small, counting the times some words appear at each article. Im trying to submit, to an autograder for homeworks, but i get 18 lines mismatched, im new to bash, so i hope someone can help fill a break case or give a suggestion to try to improve the script, thanks
`
#!/bin/bash
site= “site link“
data=$(wget –no-check-certificate -q -0 – $site 2>/dev/null)
articles=$(echo “§data” | grep -oP “desired link /[0-9a-zA-Z]+”)
Uniqarticles=$(echo “$articles” | sort | uniq)
words=(some desired words)
for url in $uniqarticles; do
Retrieve article content
article_content=$(wget –no-check-certificate -q -0 – “$url” 2>/dev/null)
output=”$url”
nonzero=false # Flag to track if any non zero count is found in the article
for word in “${words[@l}”; do
count=$(echo “$article_content” | grep -o -i “$word” | we – 1)
if [[ $count -ne 0 ]l; then
output=”Soutput, $word, $word” # Include the name and count in output
nonzero=true # Set nonzero to true if any nonzero is found
fi
done
if ! $nonzero; then
output=”$url, -” # Set output to include a dash if all zero
fi
echo “$output”
done`
Yazan Sarhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.