3

[sed] Replace reStructuredText Link by Regular Expression

 2 years ago
source link: http://siongui.github.io/2016/03/30/sed-replace-rst-link-via-regular-expression/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[sed] Replace reStructuredText Link by Regular Expression

March 30, 2016

Make reStructuredText links of the same name anonymous via regular expression by sed stream editor.

`頁4 <http://www.chilin.edu.hk/edu/report_section_detail.asp?section_id=59&id=274&page_id=156:0>`_ => `頁4 <http://www.chilin.edu.hk/edu/report_section_detail.asp?section_id=59&id=274&page_id=156:0>`__

$ sed -r 's/(`頁4 <[^>]+>`)_/\1__/g' -i content/articles/tipitaka/sutta/diigha/dn22/contrast-reading%zh.rst

Result:

link.diff | repository | view raw

diff --git a/content/articles/tipitaka/sutta/diigha/dn22/contrast-reading%zh.rst b/content/articles/tipitaka/sutta/diigha/dn22/contrast-reading%zh.rst
index 2159789..77ffa64 100644
--- a/content/articles/tipitaka/sutta/diigha/dn22/contrast-reading%zh.rst
+++ b/content/articles/tipitaka/sutta/diigha/dn22/contrast-reading%zh.rst
@@ -126,7 +126,7 @@
 
 .. [2] 〔註002〕 本譯文請參考:`念住大經;莊春江 <dn.22-ChuangCJ.html>`__ [原始出處請參考:`臺灣【莊春江工作站】 <http://agama.buddhason.org/index.htm>`__ → `漢譯長部/Dīghanikāyo <http://agama.buddhason.org/DN/index.htm>`__ → 22 → \ `長部22經/念住大經(大品[第二]); 莊春江 <http://agama.buddhason.org/DN/DN22.htm>`__ 02/20/2015 17:12:44 更新]。
 
-.. [3] 〔註003〕 本譯文請參考:`長部.二十二.大念處經;蕭式球 <dn.22-SiuSK.html>`__ 〔原始出處請參考:\ `香港【志蓮淨苑】文化部--佛學園圃--5. 南傳佛教 <http://www.chilin.edu.hk/edu/report_section.asp?section_id=5>`__--5.1. 利文佛典選譯-- 5.1.1.長部 → 22 大念處經 → \ `長部.二十二.大念處經;蕭式球 <http://www.chilin.edu.hk/edu/report_section_detail.asp?section_id=59&id=274>`_ \ ,頁1~ \ `頁4 <http://www.chilin.edu.hk/edu/report_section_detail.asp?section_id=59&id=274&page_id=156:0>`_ \ ) (或\ `志蓮淨苑文化部--研究員工作--研究文章 <http://www.chilin.edu.hk/edu/work_paragraph.asp>`__--南傳佛教 → 22 大念處經 → `長部.二十二.大念處經;蕭式球 <http://www.chilin.edu.hk/edu/work_paragraph_detail.asp?id=274>`__\ ,頁1~ \ `頁4 <http://www.chilin.edu.hk/edu/work_paragraph_detail.asp?id=274&page_id=156:0>`_ \ )〕
+.. [3] 〔註003〕 本譯文請參考:`長部.二十二.大念處經;蕭式球 <dn.22-SiuSK.html>`__ 〔原始出處請參考:\ `香港【志蓮淨苑】文化部--佛學園圃--5. 南傳佛教 <http://www.chilin.edu.hk/edu/report_section.asp?section_id=5>`__--5.1. 利文佛典選譯-- 5.1.1.長部 → 22 大念處經 → \ `長部.二十二.大念處經;蕭式球 <http://www.chilin.edu.hk/edu/report_section_detail.asp?section_id=59&id=274>`_ \ ,頁1~ \ `頁4 <http://www.chilin.edu.hk/edu/report_section_detail.asp?section_id=59&id=274&page_id=156:0>`__ \ ) (或\ `志蓮淨苑文化部--研究員工作--研究文章 <http://www.chilin.edu.hk/edu/work_paragraph.asp>`__--南傳佛教 → 22 大念處經 → `長部.二十二.大念處經;蕭式球 <http://www.chilin.edu.hk/edu/work_paragraph_detail.asp?id=274>`__\ ,頁1~ \ `頁4 <http://www.chilin.edu.hk/edu/work_paragraph_detail.asp?id=274&page_id=156:0>`__ \ )〕
 
 .. [4] 〔註004〕 本譯文請參考:\ `大念處經;明法比丘 <dn.22.metta-pc.html>`_ \ (Bhikkhu Metta, Taiwan) (巴漢對照及文法分析); \ `PDF <dn.22.metta-pc.pdf>`_ \ [原始出處請參考: \ `法雨道場 <http://www.dhammarain.org.tw/>`_ \ → \ `閱讀三藏 <http://www.dhammarain.org.tw/canon/canon1.html>`_ \ →  大念處經 -- (巴漢對照及文法分析) -- Edited by **Ven. Bhikkhu Metta明法比丘**\(Taiwan); \ `另一鏡像站: dhammarain.online-dhamma.net <http://dhammarain.online-dhamma.net>`_ \ ]
 

Note that use 's/(`頁4 <.+>`)_/\1__/g' instead of 's/(`頁4 <[^>]+>`)_/\1__/g' will match only one link because the match is greedy. See [1] for more details.


Tested on Ubuntu Linux 15.10, sed 4.2.2-6.1.


References:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK