サンプルマークダウンファイル:
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)