ウェブサイトの特定の行でカールを実行する方法は?

ウェブサイトの特定の行でカールを実行する方法は?

カーリングしようとしています。 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

ベストアンサー1

努力するawk

curl -s 'https://en.wikipedia.org/wiki/World_Happiness_Report?action=raw' \
| awk  '
    /^===2018 report===/{p=1}
    /^\| 11\|\|/{p=0}
    p'
  • 私達は出力を使用してcurlパイプします。awkcurl ... | awk ...
  • awkpスクリプトは、行の先頭が一致した場合に変数を(true)に設定し、行の先頭が一致した場合(false)に設定します。 1 の場合、対応する行が印刷されます。1===2018 report===0|11 ||p

おすすめ記事