Loading ...
Sorry, an error occurred while loading the content.

84522Re: regexp to identify N duplicates parts into several lines

Expand Messages
  • Ben Schmidt
    Nov 1, 2007
    • 0 Attachment
      > Hi,
      > I have a file formatted into CSV and the first column take the name of
      > files.
      > I would like to copy all lines which have the same file name to the
      > end of the file by regexp.
      > g/\(^[^/]\+;\)\(.*\n\)\(\(^\1\)\(.*\n\)\)\{1,\}/t$
      > This regexp search highlights correctly the three first lines because
      > there is three times sortie.cpp,
      > it highlights the three lines after because there is three sortie.h
      > but it does not copy all highlighted at the end of the file.
      > It copies only the first occurence and I would copy all occurences.
      > why ?

      Actually, my previous suggestion won't work when there are more than two duplicate
      lines, I don't think, as it will run on each line except the last...hmmm...

      This would be a problem with your original command, too, though.

      You will probably want to consider a more complicated solution again, like
      scripting the whole thing, which would be fairly easy: e.g.:

      function! GetDuplicates()
      let lastline=line('$')
      let prevkey=""
      let curline=1
      let copiedkey=0
      while curline <= lastline
      let thiskey = matchstr(getline(curline),'^[^;]*;')
      if thiskey == prevkey
      if copiedkey == 0
      execute (curline-1)."t$"
      let copiedkey = 1
      execute curline."t$"
      let copiedkey = 0
      let curline = curline + 1
      let prevkey = thiskey

      I've barely tested it, but it shouldn't be too far wrong!



      Send instant messages to your online friends http://au.messenger.yahoo.com

      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
    • Show all 8 messages in this topic