Non greedy pattern match in sed
Paul Bryan
pa_bryan at yahoo.co.uk
Tue Aug 13 20:57:20 EST 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This is from the do it with sed
(http://www.dbnet.ece.ntua.gr/~george/howto/sed/sedtut_1.html):
I haven't tried it out, but from a casual glance it looks reasonable...
- ------------------------------------------------------------------------
Delete comments from C code
- ------------------------------------------------------------------------
#!/usr/bin/sed -f
# if no /* get next
/\/\*/!b
# here we've got an /*, append lines until get the corresponding
# */
:x
/\*\//!{
N
bx
}
# delete /*...*/
s/\/\*.*\*\///
On Tue, 13 Aug 2002 16:25, Michael Still wrote:
> Hey,
>
> I would like non greedy regexp matching in sed.
>
> i.e.
>
> echo "/* This is a */ test /* line */" | sed 's/\/\*.*\*\//g'
> ^^
> Non greedy toggle
> here?
>
> Should result in:
>
> " test "
>
> Any hints?
>
> Thanks,
> Mikal
- --
Paul Bryan
E-Mail: pa_bryan at yahoo.co.uk
PGP Key
http://www.keyserver.net:11371/pks/lookup?op=get&search=0xB1D405DA
Fifth Law of Procrastination:
Procrastination avoids boredom; one never has the feeling that
there is nothing important to do.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE9WOYT3qGyTLHUBdoRAo2JAKDFkSQpu6BNsxXcNK+eoqr8h1m87ACdENDc
iO741joTMdfEe7d8qDZ2HTU=
=ui3L
-----END PGP SIGNATURE-----
More information about the linux
mailing list