Discussion:
find strings and add text
Rachid Mokrani rachid.mokrani@gmail.com [sed-users]
2017-05-20 17:08:24 UTC
Permalink
Hi,


I can not find a simple sed command that will allow me to do this.

echo "221b Baker St, Marylebone, 32861 London"


Need to add caracter ";" before and after the number with 5 digit only

Need result.

221b Baker St, Marylebone, ; 32861 ; London

Some suggestion.
Best regards.


[Non-text portions of this message have been removed]
Christopher Stone listmeister@thestoneforge.com [sed-users]
2017-05-20 18:01:47 UTC
Permalink
Post by Rachid Mokrani ***@gmail.com [sed-users]
I can not find a simple sed command that will allow me to do this.
echo "221b Baker St, Marylebone, 32861 London"
221b Baker St, Marylebone, ; 32861 ; London
______________________________________________________________________

Hey Rachid,

If your version of sed supports word-boundaries then this is simple:

---------------------------------------------------

#!/usr/bin/env bash

strVar='221b Baker St, Marylebone, 32861 London'

gsed -r 's!\b([0-9]{5})\b! ; \1 ; !' <<< "$strVar"

---------------------------------------------------

If it doesn't then please tell us what OS and what version of sed you're using.

--
Best Regards,
Chris
Thierry Blanc Thierry.Blanc@gmx.ch [sed-users]
2017-05-21 06:58:41 UTC
Permalink
if only the postcode has 5 digits, it seems fairly easy:
sed -r 's|[0-9]{5} |; &; |'
Post by Christopher Stone ***@thestoneforge.com [sed-users]
Post by Rachid Mokrani ***@gmail.com [sed-users]
I can not find a simple sed command that will allow me to do this.
echo "221b Baker St, Marylebone, 32861 London"
221b Baker St, Marylebone, ; 32861 ; London
______________________________________________________________________
Hey Rachid,
---------------------------------------------------
#!/usr/bin/env bash
strVar='221b Baker St, Marylebone, 32861 London'
gsed -r 's!\b([0-9]{5})\b! ; \1 ; !' <<< "$strVar"
---------------------------------------------------
If it doesn't then please tell us what OS and what version of sed you're using.
--
Best Regards,
Chris
------------------------------------
------------------------------------
------------------------------------

------------------------------------
--
------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/sed-users/join
(Yahoo! ID required)

<*> To change settings via email:
sed-users-***@yahoogroups.com
sed-users-***@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
sed-users-***@yahoogroups.com

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/
Loading...