Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:44:33+00:00 2026-06-05T01:44:33+00:00

I would like to edit my hosts file to match my current IPs, I

  • 0

I would like to edit my hosts file to match my current IPs, I could do it in Python or AWK, but I was wondering if there is a way in VIM…

let’s see what I mean, my hosts looks like that:

192.168.11.172    blazer blazer.mydomain
192.168.11.173    faster faster.mydomain
...
192.168.11.225    schurtig schurtig.mydomain

Now, I want to increment every IP by 32 so the end result would be:

192.168.11.202    blazer blazer.mydomain
192.168.11.203    faster faster.mydomain
...
192.168.11.257    schurtig schurtig.mydomain

If I put my cursor on the right IP, and type

30 and CTRL+A

it does what I want.

The only problem, I have about 300 hosts … and I need to do it once every 3 months …
Although I could do it in Python, seeing the file in vim feels safer, because I don’t need to run a script and then control the result after that.

The following changes only the first line:

let i=172 | g/172/s//\=i+30/

I want to repeat this in a loop for different IP ranges being able to say how many times i should be incremented, is there a “trick” that does that?

Thanks in advance for the efforts,
Oz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:44:34+00:00Added an answer on June 5, 2026 at 1:44 am

    Try this:

    :let i=30 | %s/^\(\d*\.\d*\.\d*\.\)\(\d*\)/\=submatch(1).(submatch(2)+i)
    

    \(\d*\.\d*\.\d*\.\) (retrieved by submatch(1)) matches the IP first three numbers and dots (eg 192.168.11.) and \(\d*\) (retrieved by submatch(2)) matches the IP last number.

    I think this is a better way to control it:

    :let i=30 | %s/^\(\d*\.\d*\.\d*\.\)\(\d*\)/\=submatch(1).(submatch(2)+i)/gc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how I could edit mp3 files on the server
I would like to know if it's possible to edit a file from within
I would like to edit matlab scripts in two cases (1) In matlab Command
I'm working in Visual Studio 2008 and I would like for Edit > Outlining
I would like to write a script which will edit multiple XML files, I
I would like the user to be able to edit the title of the
It is possible to group some fields in the edit form? I would like
I wonder if there is a way for me to SCP the file from
all. I'm working on software to block ads using the system's hosts file, but
This seems like such a ridiculous question, but our intranet portal which hosts hundreds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.