Curl
如何從網站的特定行捲曲?
我正在嘗試從 https://en.wikipedia.org/wiki/World_Happiness_Report?action=raw捲曲到我的文件我只想要 ===2018 報告=== 部分
這是我寫的
curl curl https://en.wikipedia.org/wiki/World_Happiness_Report?action=raw >> a1t4.txt
但是它把這個網站上的所有內容我想要的只是這一部分
===2018 report=== The 2018 report features the happiness score averaged over the years 2015–2017. As per the 2018 Happiness Index, [[Finland]] is the 'happiest' country in the world. [[Norway]], [[Denmark]], [[Iceland]] and [[Switzerland]] hold the next top positions. The report was published on 14 March 2018 by UN. The full report can be read at [http://worldhappiness.report/ed/2018/ 2018 Report]. The World Happiness Report is a landmark survey of the state of global happiness. The World Happiness Report 2018, which ranks 156 countries by their happiness levels, and 117 countries by the happiness of their immigrants, was released on March 14 at a launch event at the Pontifical Academy of Sciences in the Vatican. {{collapse top|title=Table}} {| class="wikitable sortable" |- valign=top ! style="width: 10px;" | Overall rank ! style="width: 250px;" | Country or region ! {{abbr|Score|Happiness score}} ! style="width: 10px;" | {{abbr|GDP per capita|Explained by: GDP }} ! style="width: 10px;" | {{abbr|Social support|Explained by: Social support}} ! style="width: 10px;" | {{abbr|Freedom to make life choices|Explained by: Freedom to make life choices}} ! style="width: 10px;" | {{abbr|Generosity|Explained by: Generosity}} ! style="width: 10px;" | {{abbr|Perceptions of corruption|Explained by: Perceptions of corruption}} |- | 1||{{flag|Finland}}||7.632||1.305||1.592||0.874||0.681||0.202||0.393 |- | 2||{{flag|Norway}}||7.594||1.456||1.582||0.861||0.686||0.286||0.340 |- | 3||{{flag|Denmark}}||7.555||1.351||1.590||0.868||0.683||0.284||0.408 |- | 4||{{flag|Iceland}}||7.495||1.343||1.644||0.914||0.677||0.353||0.138 |- | 5||{{flag|Switzerland}}||7.487||1.420||1.549||0.927||0.660||0.256||0.357 |- | 6||{{flag|Netherlands}}||7.441||1.361||1.488||0.878||0.638||0.333||0.295 |- | 7||{{flag|Canada}}||7.328||1.330||1.532||0.896||0.653||0.321||0.291 |- | 8||{{flag|New Zealand}}||7.324||1.268||1.601||0.876||0.669||0.365||0.389 |- | 9||{{flag|Sweden}}||7.314||1.355||1.501||0.913||0.659||0.285||0.383 |- | 10||{{flag|Australia}}||7.272||1.340||1.573||0.910||0.647||0.361||0.302
嘗試
awk
:curl -s 'https://en.wikipedia.org/wiki/World_Happiness_Report?action=raw' \ | awk ' /^===2018 report===/{p=1} /^\| 11\|\|/{p=0} p'
- 我們將輸出從管道
curl
傳輸到awk
使用curl ... | awk ...
awk
腳本將在行首匹配時將變數設置p
為1
(true),在行首匹配時將變數設置===2018 report===
為0
(false)|11 ||
。p
只要為 1 ,它將列印該行。