[CLUE-Tech] vi search/replace question
Jeff Cann
j.cann at isuma.org
Fri Apr 23 08:23:58 MDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thursday 22 April 2004 10:54 am, Dave Price wrote:
> For example, I want to remove all the lines the start with a particular
> character, perhaps #, (so the regex to find the lines would be ^# ...
>
> How can I tell vi to replace the regex and the rest of the line with
> 'nothing'?
Dave,
You can do this in vi, for line 30:
:30 /^#.*//
the ^# (as you know) is the front of line (hidden) character and the comment #
the . matches any single character
the * modifies the . to match any number of . characters
the replacment is simply two slashes // which is 'nothing'
or for every line in a file:
:%s /^#.*//
>
> I know I could do this easily by piping the file out to grep -i, but
> lets just say I don't have a good grep available under this OS.... Or I
> just want to learn to do this entirely in vi.
A quicker way to do this for a number of files is using perl:
$ perl -pi -e 's/^#.*//' (list of files)
Later,
Jeff
- --
"Faith that does not affect a person's culture is a faith not fully embraced,
not entirely thought out, not faithfully lived."
- - Pope John Paul II
http://isuma.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQFAiScCi4b9OApLCmoRAjalAJsHJPoQSI8P1vQJTFbqHWXKf0sd9wCglUrO
pnxsrQbMjhbcmUrNsP32GVw=
=HpQF
-----END PGP SIGNATURE-----
More information about the clue-tech
mailing list