On 06/07/11 11:02, Stefan Klein wrote:
Hi vim users,

i got a longer SQL script with duplicate inserts :/
I'd like to remove those without sorting the whole file.
It's possible to match the lines by a pattern.

One solution might be to insert the line number at the end of the line,
sort the file,
delete duplicate lines ignoring the linenumber,
move the line number to the start of the line,
sort,
remove the line number.

Is there a more simple way?

thanks,
Stefan


well, maybe, but probably not as fast since its processing time would be on the order of the square of the number of lines: simply write a function with a double loop, which would examine all lines 1→$ in turn in the outer loop then compare it with all following lines $→(i+1) in turn in an inner loop, and delete the later line if equal. Scanning forward in the outer loop and backward in the inner loop ensures that you don't get line numbers changed before you have finished using them. But the end-of-loop test for the outer loop must recompute line('$') at every interation.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
124. You begin conversations with, "Who is your internet service provider?"

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to