I have the followinf text:
我有以下文字:
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
How can I use sed to match the dates "mm/yy" format and alter to "|mm/yy|"
如何使用sed匹配日期“mm / yy”格式并更改为“| mm / yy |”
Like: 11 Cherrywood Rise Ashford Kent TN25 4QA United Kingdom N B BONE|02/12|387
喜欢:11 Cherrywood Rise Ashford Kent TN25 4QA英国N B BONE | 02/12 | 387
Thanks!
谢谢!
2 个解决方案
#1
2
does this work for you?
这对你有用吗?
sed -r 's# ([0-9]{2}/[0-9]{2}) #|\1|#' file
#2
1
Example 1
例1
cat t.txt | sed -E 's/([0-9]{2}\/[0-9]{2})/|\1|/g'
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
11 Cherrywood Rise Ashford Kent TN25 4QA英国NB 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 NP SALTMARSH(04/13) 907 116 Long Acre London London WC2E 9SU英国Lorna J Gradden(11/14)415
or
要么
sed -E 's/([0-9]{2}\/[0-9]{2})/|\1|/g' t.txt
#1
2
does this work for you?
这对你有用吗?
sed -r 's# ([0-9]{2}/[0-9]{2}) #|\1|#' file
#2
1
Example 1
例1
cat t.txt | sed -E 's/([0-9]{2}\/[0-9]{2})/|\1|/g'
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
11 Cherrywood Rise Ashford Kent TN25 4QA英国NB 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 NP SALTMARSH(04/13) 907 116 Long Acre London London WC2E 9SU英国Lorna J Gradden(11/14)415
or
要么
sed -E 's/([0-9]{2}\/[0-9]{2})/|\1|/g' t.txt