On Mar 22, 2011, at 3:33 PM, Dennis Benzinger wrote: > Hi! > > I have a log file with timestamps and messages: > > 01:00 x > 02:00 y > 03:00 z > > To compare the time elapsed between two events I want to prefix each line > with the timestamp of the previous time. I tried to use > > %s/^/\=matchstr(getline(line(".")-1), "\\d\\{2}:\\d\\{2} ") > > but somehow the first match is prepended to every line: > > 01:00 x > 01:00 02:00 y > 01:00 03:00 z > > A larger example would be the file > > http://www.rfc-editor.org/in-notes/rfc-index.txt > > with the command > > %s/^/\=matchstr(getline(line(".")-1), "\\d\\{4} ") > > The first match 1129 from line 24 is prepended to every following line. > > > Where is the problem?
When you substitute line 3, it gets the first time stamp if finds in line 2, so I modified line 1 and search pattern like this: 00:00 01:00 x 02:00 y 03:00 z :%s/^/\=matchstr(getline(line(".")-1), '\d\{2}:\d\{2} \zs\d\{2}:\d\{2} ') And it seems to work. Israel -- 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