On Wed, 21 Jul 2010, rudy_b wrote:

> 
> Hi all, 
> I would truley thank you if you can help me with my issue. It's been few
> hours I am trying to solve this, but no luck yet!! 
> 
> I want to do a substitution using the (/s) command. But I am ONLY interested
> in substituting multiples of 100th line. 
> In other words, I have a huge file (thousands of lines); and, I want to go
> through this file, and look for lines #100, #200, #300, #400, ... and append
> the word "checked" at the end of these line. 
> for example: 
> 1. this is my line #1 
> 2. this is my line #2 
> 3. this is my line #3 
> ... 
> 100. this is my line #4 (CHECKED) 
> 101. this is my line #101 
> ... 
> 199 this is my line #199 
> 200. this is my line #200 (CHECKED) 
> ... 
> and so on... 
> 
> Does anyone know how can I do this? 

The following works for me:

%s/$/\=line('.') % 100 ? "" : " (CHECKED)"/

explanation:
%                                - for all lines
s/$                              - change the end of the line
/\=                              - to the expression:
line('.') % 100                  - will be 0 on lines divisible by 100
                ? ""             - no change (when not 0)
                                : " (CHECKED)"   - change (when 0)

Might be a nicer way to do it, but the:

(condition) ? "" : "something"

expression is pretty flexible.

-- 
Best,
Ben

-- 
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