bsteo
bsteo

Reputation: 1779

GNU Sed REGEX find and alter string (no replace)

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|"

Like: 11 Cherrywood Rise Ashford Kent TN25 4QA United Kingdom N B BONE|02/12|387

Thanks!

Upvotes: 0

Views: 92

Answers (2)

James Kyburz
James Kyburz

Reputation: 14473

Example 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

or

sed -E 's/([0-9]{2}\/[0-9]{2})/|\1|/g' t.txt

Upvotes: 1

Kent
Kent

Reputation: 195189

does this work for you?

sed -r 's# ([0-9]{2}/[0-9]{2}) #|\1|#' file

Upvotes: 2

Related Questions