0

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: \[\[(.+?)\]\]

3 Answers 3

1

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.

1

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.
1
  • Probably safer to use '[^]]*' in place of '.*' in case there are two fields with the double-square brackets around them. Nov 1, 2009 at 20:00
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .