vote up 0 vote down star

I have a large table from Wikipedia (from the wiki source), and I want to extract a single column, I have it open in vim, and what I want to extract looks something like this

|col||[[what I want]]||another column||another one||et cetera|

Every line has content I want, so I tried:

:%s/\[\[(.+?)\]\]/\1

But I get the error

E486: Pattern not found: \[\[(.+?)\]\]
flag

3 Answers

vote up 1 vote down check

I would cut the content out first, then open it in vi:

cat wikifile.txt | cut -d \| -f 4 > foo
vi foo

Two steps, but two steps I can always remember without much thought.

link|flag
vote up 1 vote down

Try

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

which will return

what i want

I.e. you need to

  • escape the group brackets "(" and ")" and also
  • match the part before and after the interesting column because you want to replace it.
link|flag
Probably safer to use '[^]]*' in place of '.*' in case there are two fields with the double-square brackets around them. – Jonathan Leffler Nov 1 at 20:00
vote up 0 vote down

Is this what you want :

1,$ s/^\(.*\[\[\)\(.*\)\(\]\].*\)$/\2/

It check from the begin of the line to [[ -> put it in atom 1, the sentence -> atom 2, the end of line -> atom 3.

Then just display atom 2.

link|flag

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.