Regex GNU-Sed正则表达式查找和更改字符串(无替换)
我有以下案文:Regex GNU-Sed正则表达式查找和更改字符串(无替换),regex,sed,Regex,Sed,我有以下案文: 11 Cherrywood Rise Ashford Kent TN25 4QA United Kingdom N B BONE 02/12 387 Bisham village Bisham Buckinghamshire SL7 1RR United Kingdom Neil Noakes 06/13 488 6 Kynaston Road London London N16 0EX United Kingdom MR N P SALTMARSH 04/13 907 116
11 Cherrywood Rise Ashford Kent TN25 4QA United Kingdom N B BONE 02/12 387
Bisham village Bisham Buckinghamshire SL7 1RR United Kingdom Neil Noakes 06/13 488
6 Kynaston Road London London N16 0EX United Kingdom MR N P SALTMARSH 04/13 907
116 Long Acre London London WC2E 9SU United Kingdom Lorna J Gradden 11/14 415
如何使用sed匹配日期“mm/yy”格式并更改为“|mm/yy |”
比如:11切利伍德路阿什福德肯特TN25 4QA英国北伯尼| 02/12 | 387
谢谢 这对你有用吗
sed -r 's# ([0-9]{2}/[0-9]{2}) #|\1|#' file
这对你有用吗
sed -r 's# ([0-9]{2}/[0-9]{2}) #|\1|#' file
例1
cat t.txt | sed -E 's/([0-9]{2}\/[0-9]{2})/|\1|/g'
11 Cherrywood Rise Ashford Kent TN25 4QA英国北部BONE(2012年2月)387
比沙姆村比沙姆白金汉郡SL7 1RR英国尼尔·诺克斯(06/13)488
伦敦Kynaston路6号伦敦N16 0EX英国N P SALTMARSH先生(04/13)907
116长英亩伦敦WC2E 9SU英国洛娜·J·格拉登(11/14)415
或
例1
cat t.txt | sed -E 's/([0-9]{2}\/[0-9]{2})/|\1|/g'
11 Cherrywood Rise Ashford Kent TN25 4QA英国北部BONE(2012年2月)387
比沙姆村比沙姆白金汉郡SL7 1RR英国尼尔·诺克斯(06/13)488
伦敦Kynaston路6号伦敦N16 0EX英国N P SALTMARSH先生(04/13)907
116长英亩伦敦WC2E 9SU英国洛娜·J·格拉登(11/14)415
或
请求的格式是|02/12 |
,请求的格式是|02/12 |