A vi question
Fabian Bruns
fabian_bruns at gmx.de
Wed Sep 16 16:39:03 UTC 2009
On Tue, Sep 08, 2009 at 02:35:31PM -0400, stan wrote:
> vi is a continuing learning experinece :-)
>
> The lesson I would like to learn today is given a file containing lines of
> this format:
>
> SOR XIC I:016/0 BST OTE B3/200 NXB OTE N51:4/13 BND EOR
>
> I need to delete evrything on each line _before_ the OTE. The strings
> preceding the OTE are vairable. So I need a command that saya:
>
> for each line find everyhting from the begining of the line through OTE,
> and substitue OTE for it. or at leat that's one idea I had. I am ceratin
> there is more than one way to solve this problem.
>
> I was thinking that I needed something like:
>
> :.,$s/^*OTE/OTE/
>
> But * is not the appropriate wildcard here in vi.
>
> Any sugestions?
>
> --
> One of the main causes of the fall of the roman empire was that, lacking
> zero, they had no way to indicate successful termination of their C
> programs.
>
in Vi/VIM, * is not a wildcard as you would use them in the shell, Vi
is using regular expressions.
(There are lots of good tutorials on regex, and it's very useful to
learn the basics of it).
You need to prepend a ., making it
:.,$s/^.*OTE/OTE/
The . means "arbitrary character", the * means "zero times or more the
pattern before it"
Also, if you want to replace in the whole file at once, you can use % as a
region instead of .,$
--
| Fabian Bruns
>
| jabber: FnordPerfect at jabber.org Twitter: @FnordPerfect ICQ: 30934149
`--- -- - - -
More information about the ubuntu-users
mailing list