컬링하려고 하는데 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
파이프 합니다.awk
curl ... | awk ...
awk
p
스크립트는 줄의 시작 부분이 일치할 때 변수를 (true)로 설정하고 줄의 시작 부분이 일치할 때 (false)로 설정합니다. 1이면 해당 줄이 인쇄됩니다.1
===2018 report===
0
|11 ||
p