Portál AbcLinuxu, 10. května 2025 09:06
Řešení dotazu:
url='http://aktualne.centrum.cz/zahranici/evropa/clanek.phtml?id=653920' wget -O clanek.html "$url" titulek=`grep -o '<h1 class="titulek-clanku">[^<]*' clanek.html | cut -c28-` cas_datum=`grep -o '<span class="cas">[^<]*' clanek.html | head -n1` cas=`echo "$cas_datum" | grep -Eo '[0-9]{2}:[0-9]{2}'` datum=`echo "$cas_datum" | grep -Eo '[0-9]{2}\.[0-9]{2}\.[0-9]{4}'` echo -e "Titulek: $titulek\nCas: $cas, Datum: $datum"
url='http://aktualne.centrum.cz/zahranici/evropa/clanek.phtml?id=653920' wget -q -O - "$url" | iconv -f iso8859-2 -t utf-8 > clanek.html titulek=$(sed -n -e 's/.*<h1 class="titulek-clanku">\([^<]*\).*/\1/p' clanek.html) datum=$(sed -n -e 's/.*titulek-clanku.*<span class="cas">[^|]*|[^0-9\.]*\([0-9\.]*\).*/\1/p' clanek.html) cas=$(sed -n -e 's/.*titulek-clanku.*<span class="cas">\s*\([0-9:]*\).*$/\1/p' clanek.html) echo -e "Titulek: $titulek\nCas: $cas, Datum: $datum"Obecně lze kombinaci grep/head/cut omezit na sed.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.