샘플 마크다운 파일:
cat index.md
# Abstract
- To achieve [Work Life Balance](./WorkLifeBalance/WorkLifeBalance.md), first understand what it means and what are the requirements.
- Develop right **[Attitude](./Attitude/index.md)** and [Haha](./Haha/Haha.md).
- Understand **[attention](./AttentionManagement/index.md)**, **[time](./TimeManagement/index.md)** and **[task](./TaskManagement/index.md)** management and start implementing those.
예상되는 결과
[Work Life Balance](./WorkLifeBalance/WorkLifeBalance.md)
[Attitude](./Attitude/index.md)
[Haha](./Haha/Haha.md)
[attention](./AttentionManagement/index.md)
[time](./TimeManagement/index.md)
[task](./TaskManagement/index.md)
해결하려고 노력하다
sed -r -n -e 's/.*(\[.*\]\(.*\)).*/\1/p' index.md
, 그러나 이는 연속된 마지막 링크에만 일치합니다!
제안?
저는 sed를 선호하지만, sed가 이를 수행하지 못한다면 다른 도구를 사용해도 됩니다.
답변1
내 솔루션:
sed -r -e 's/\[/\n[/g' index.md | sed -r -e 's/.*(\[.*\]\(.*\)).*/\n\1/g' | grep -oE '\[.*\]\(.*\)'
답변2
사용sed
$ sed -En '/\[/{s/[^[]*(\[[^)]*\))[^[]*/\1/g;/\[[^[]*\[/s/\[[^)]*\)/\n&/2g;p}' input_file
[Work Life Balance](./WorkLifeBalance/WorkLifeBalance.md)
[Attitude](./Attitude/index.md)
[Haha](./Haha/Haha.md)
[attention](./AttentionManagement/index.md)
[time](./TimeManagement/index.md)
[task](./TaskManagement/index.md)