Re: Regex for white space

From: Lew Pitcher (Lew.Pitcher_at_td.com)
Date: 11/23/05


Date: Wed, 23 Nov 2005 14:48:15 -0500


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ying Zu wrote:
> Suppose a series of white spaces in between a string, just like"
>
> "foo fooo foooo fooooo"
>
> Now I wonder how can I get a new string contains no spaces or substuted by symbols like _

tr(1) or sed(1) should do

  pitchl@srdscs05:~$ echo "foo fooo foooo fooooo" | tr '[:blank:]' '_'
  foo_fooo_foooo__fooooo

  pitchl@srdscs05:~$ echo "foo fooo foooo fooooo" | tr -d '[:blank:]'
  foofooofoooofooooo

  pitchl@srdscs05:~$ echo "foo fooo foooo fooooo" \
                     | sed 's/[[:blank:]]/_/g'
  foo_fooo_foooo__fooooo

  pitchl@srdscs05:~$ echo "foo fooo foooo fooooo" \
                     | sed 's/[[:blank:]]//g'
  foofooofoooofooooo

> Maybe a simple regex use but I am a newbie in shell script...
>
> thanks :)

- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFDhMd+agVFX4UWr64RApb1AKCTiSzvVRgLB4T414bfNUpJNg7IcQCfZQju
w4MiH/PxbomL5Z46WePz0y8=
=iblw
-----END PGP SIGNATURE-----



Relevant Pages

  • Re: How can i Right Trim all the spaces of a very long (2000 chars) Charecter string ?
    ... > Right Trim Function in c,using Binary search kind of fast algorithm? ... > Start from the right most charecter of the string to the left of the ... Is the string allowed to contain white spaces in the significant part? ...
    (comp.lang.c)
  • Re: VB help
    ... retrieving the a srting value in the database through a record ... retrieved string shows some junk charecters in place of white spaces ... string in the database 8a Church Road Barry ...
    (microsoft.public.vb.general.discussion)
  • Re: Regex for white space
    ... Ying Zu wrote: ... > Suppose a series of white spaces in between a string, ... > Now I wonder how can I get a new string contains no spaces or substuted by symbols like _ ... BashDiff: Super Bash shell ...
    (comp.unix.shell)
  • Re: Is there any function as Trim in Jscript/JavaScript?
    ... > Is there any function as Trim in Jscript/JavaScript? ... > not find anything untill now. ... > a string with some or a lot of white spaces. ...
    (microsoft.public.scripting.jscript)

Loading