Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extract column in vi

20 views
Skip to first unread message

Nagendra...@gmail.com

unread,
Apr 21, 2009, 5:24:28 AM4/21/09
to
Hi,

I am new user to gVim and i love this tool. Currently i am trying to
replace all the columns except the last one with blank.

How can i achieve this in vim? I don't want to redirect the output to
new file i am using this as a notepad replacement.

-rw-r--r-- 1 oracle dba 199 Jun 26 2007 temp.lst
-rw-r--r-- 1 oracle dba 289093 Jun 26 2007 abcd.lst
-rw-r--r-- 1 oracle dba 128368 Sep 22 2007 138.lst
-rw-r--r-- 1 oracle dba 128368 Sep 30 2007 133.lst
-rw-r--r-- 1 oracle dba 145893 Dec 31 2007 149.lst
-rw-r--r-- 1 oracle dba 145893 Dec 31 2007 149_1.st

The end result should be like

temp.lst
abcd.lst
139.lst
133.lst
149.lst
149_1.lst

Thanks for your help.

Regards,
Nagendra Chillale

Glenn Jackman

unread,
Apr 21, 2009, 9:58:22 AM4/21/09
to


:%s/.* //

where
% -- for every line
s/.* // -- replace all characters including the last space
with nothing

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous

Nagendra...@gmail.com

unread,
Apr 21, 2009, 11:18:35 AM4/21/09
to
On Apr 21, 6:58 pm, Glenn Jackman <gle...@ncf.ca> wrote:

Hi Glen,

temp.lst
abcd.lst
138.lst
133.lst
149.lst

This is the result i get, what i see missing is the last rows from the
column (149_1.lst)

Regards,
Nagendra Chillale

Gerard H. Pille

unread,
Apr 21, 2009, 11:56:00 AM4/21/09
to
Nagendra...@gmail.com schreef:

So maybe that line ends in a space?


Check with ":set list"

Nagendra...@gmail.com

unread,
Apr 21, 2009, 12:06:42 PM4/21/09
to
On Apr 21, 8:56 pm, "Gerard H. Pille" <g...@skynet.be> wrote:
> Nagendra.Chill...@gmail.com schreef:

Hi Gerard,

Yes that solved it. I din't read well or understand right Glen's
explanation of s/.* // -- replace all characters including the last
space with nothing.
But yes on the last line of -rw-r--r-- 1 oracle dba
145893 Dec 31 2007 149_1.st had a space and hence it was not showing
149_1.lst

Thanks Glen & Gerard appreciate your help.

Regards,
Nagendra Chillale

Glenn Jackman

unread,
Apr 21, 2009, 12:20:02 PM4/21/09
to
At 2009-04-21 11:56AM, "Gerard H. Pille" wrote:
> Nagendra...@gmail.com schreef:
> > On Apr 21, 6:58 pm, Glenn Jackman <gle...@ncf.ca> wrote:
[...]
> >> :%s/.* //
[...]

> >
> > This is the result i get, what i see missing is the last rows from the
> > column (149_1.lst)
>
> So maybe that line ends in a space?
>
>
> Check with ":set list"

Alternatively, vim has a "block select" mode: ctrl-V, so you could
select the rectangle you want to delete and hit 'x'

Nagendra...@gmail.com

unread,
Apr 21, 2009, 12:58:40 PM4/21/09
to
On Apr 21, 9:20 pm, Glenn Jackman <gle...@ncf.ca> wrote:
> At 2009-04-21 11:56AM, "Gerard H. Pille" wrote:
>
> >  Nagendra.Chill...@gmail.com schreef:

> > > On Apr 21, 6:58 pm, Glenn Jackman <gle...@ncf.ca> wrote:
> [...]
> > >>     :%s/.* //
> [...]
>
> > > This is the result i get, what i see missing is the last rows from the
> > > column (149_1.lst)
>
> >  So maybe that line ends in a space?
>
> >  Check with ":set list"
>
> Alternatively, vim has a "block select" mode:  ctrl-V, so you could
> select the rectangle you want to delete and hit 'x'
>
> --
> Glenn Jackman
>     Write a wise saying and your name will live forever. -- Anonymous

Hi Glen,

Unfortunately in gVim (While in visual mode) ctrl-V result in pasting
of data in the clipboard if thats what it uses to paste.

Regards,
Nagendra Chillale

OldSchool

unread,
Apr 21, 2009, 1:51:18 PM4/21/09
to
> Nagendra Chillale- Hide quoted text -
>
> - Show quoted text -

Gvim / Windows can do block select / delete:

1) Right click on one "corner" of the block
2) in the drop down that appears, select "Select Block"
3) move cursor to the diagonal corner using the keyboard (NOT the
arrow keys)
h = left, j = down, k = up, l = right. The area should highlight
as the cursor moves
4) hit "delete key" or "x" to remove

Nagendra...@gmail.com

unread,
Apr 21, 2009, 1:54:45 PM4/21/09
to

Hi Glen,

I did figure out a way to select in block select mode in gVim. On
right clicking in gVim you get several options, one of 'em is "Select
Block" chose this. Now hold the shift key and select the rectangle and
just delete.

Regards,
Nagendra Chillale

Nagendra...@gmail.com

unread,
Apr 21, 2009, 2:34:04 PM4/21/09
to OldSchool

Hi Scott,

Yeah your exact steps is how i got it worked out. But before you could
reply :), thank you so much for the reply.

Regards,
Nagendra Chillale

Gerard H. Pille

unread,
Apr 21, 2009, 3:38:20 PM4/21/09
to
Nagendra...@gmail.com schreef:

This would have done the trick in real vi:

:%s/.* \([^ ][^ ]*\).*/\1/

0 new messages