Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Mar 2004 22:45:23 +0000
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        "Steven N. Fettig" <freebsd@stevenfettig.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: [OT] sed question
Message-ID:  <20040314224523.GA19054@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <4054DD10.5060504@stevenfettig.com>
References:  <4054DD10.5060504@stevenfettig.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--gBBFr7Ir9EOA20Yy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Mar 14, 2004 at 04:30:40PM -0600, Steven N. Fettig wrote:
> Sorry for posting an off-topic question to the list, but this is=20
> somethin that has been driving me nuts for weeks now and I can't figure=
=20
> it out.  I want to pass a text file through sed that replaces all=20
> whitespaces with a carriage return.  I.e., if I have the file=20
> my_test_text_document.txt that is a few paragraphs of writing, I want to=
=20
> take the following input:
>=20
> I have just written five paragraphs of absolute jibberish and wish that=
=20
> I could get sed to work the way that I want.  Oh how this question has=20
> plagued me!
>=20
> And have sed output:
> I
> have
> just
> written
> five
> paragraphs
> of
> absolute
> jibberish
> and
> ... you get the point.
>=20
> I can't figure out what the newline character is... I've tried \n \r &\,=
=20
> etc. with no avail.  I run the following:
>=20
> sed 's/[ ]/\n/g' my_test_text_document.txt
>=20
> and the output never has a newline added regardless of what I have=20
> substituted \n with.  I have also used " instead of ' and that hasn't=20
> helped...
> Sorry for the question, but I'd really appreciate the help!

sed(1) can do it, but it's cleaner and simpler to use tr(1):

    % cat foo
    I have just written five paragraphs of absolute jibberish and wish that=
=20
    I could get sed to work the way that I want.  Oh how this question has=
=20
    plagued me!
    % tr -s ' ' '\n' < foo
    I
    have
    just
    written
    five
    paragraphs
    of
    absolute
    jibberish
    and
    wish
    that
    I
    could
    get
    sed
    to
    work
    the
    way
    that
    I
    want.
    Oh
    how
    this
    question
    has
    plagued
    me!
   =20
	Cheers,

	Matthew

--=20
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

--gBBFr7Ir9EOA20Yy
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAVOCDdtESqEQa7a0RAmyPAJ91GZAvSiXhfeixz9BCfMctb5nIwACdHDz/
3ZCgRNLJ5eELMKi49MAmb7w=
=Cy/M
-----END PGP SIGNATURE-----

--gBBFr7Ir9EOA20Yy--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040314224523.GA19054>