Bash Assignment

1 answer below »
Answered Same DayOct 26, 2021

Answer To: Bash Assignment

Aditya answered on Oct 28 2021
127 Votes
function gettitleanddescription {

if [ ! -e /tmp/apod.html ]; then
findurlbydate
fi
    IMGDET="`
grep -o '.*' /tmp/apod.html | sed 's/\(\|<\/b>\)//g' | sed -n '2p'`"
        echo "TITLE: `grep -o '.*' /tmp/apod.html | sed 's/\(\|<\/b>\)//g' | sed -n '1p'`"
        echo " "
        echo "EXPLANATION:"
        echo " "
sed -n '/ Explanation: <\/b>/,/

/p' /tmp/apod.html |
sed -e :a -e 's/<[^>]*>//g;/ grep -Ev 'Explanation:' |
tr '\n' ' ' |
sed 's/ /\n\n/g' |
awk 'NF { print $0 "\n" }' |
sed 's/^[ \t]*//' |
sed 's/[ \t]*$//'         
        
    
        
    
        IMG="$(echo -e "${IMGDET}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
        
    
sed -n "/ $IMG <\/b>/,/<\/center>

/p" /tmp/apod.html |
sed -e :a -e 's/<[^>]*>//g;/ grep -Ev '$IMG' |
tr '\n' ' ' |
sed 's/ /\n\n/g' |
awk 'NF { print $0 "\n" }' |
sed 's/^[ \t]*//' |
sed 's/[ \t]*$//'
        

}
function findurlbydate {

    dt="$1"
    URL="http://apod.nasa.gov/apod/ap${dt}.html"
    
wget "${URL}" --quiet -O /tmp/apod.html
grep -m 1 jpg /tmp/apod.html | sed -e 's///' -e 's/.*=//' -e 's/"//g' -e 's/^/http:\/\/apod.nasa.gov\/apod\//' > /tmp/pic_url
}
#Main...

SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here