Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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: \[\[(.+?)\]\]
share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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.
share|improve this answer
    
Probably safer to use '[^]]*' in place of '.*' in case there are two fields with the double-square brackets around them. –  Jonathan Leffler Nov 1 '09 at 20:00
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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