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 9084613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:02:34+00:00 2026-06-16T21:02:34+00:00

I have a few files that contain IP addresses. I’m creating a script and

  • 0

I have a few files that contain IP addresses. I’m creating a script and have to figure out how to create a new user file with an IP address that is based off the file created before it. If the last file contains an IP of A.B.C.D the new file needs to be A.B.C.(D+4).

I think I need to use the ‘sed’ and ‘awk’ commands, but haven’t been able to get anything working. How would I go about writing this part of the script?

  • 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-16T21:02:35+00:00Added an answer on June 16, 2026 at 9:02 pm

    Here’s something to get you started: suppose there is a file called input looks like this:

    Input: contents of input

    127.0.0.1
    127.0.0.2
    127.0.0.3
    127.0.0.200
    

    You can do on the cmdline:

    awk 'BEGIN{FS=OFS="."} {$4=$4+4; print}' input > output
    

    Explanation on what awk is doing here:

    • awk '...' – invoke awk, a tool used primarily for line-by-line manipulation of files, the stuff enclosed by single quotes are instructions to awk.
    • BEGIN{FS=OFS="."} – tell awk to use . as the delimiter for both input and output. FS stands for “Field Separator”
    • {$4=$4+4; print} – $4 means the 4th field. Since . is the delimiter, D corresponds to the 4th field and we add the integer value 4 to the 4th field. The print here is just short hand for printing the entire line.
    • input – name the input file as argument to awk; save a cat
    • > output – redirect the output to a file so you can inspect them for any issues before making the user files based on it.

    Output: contents of output

    127.0.0.5
    127.0.0.6
    127.0.0.7
    127.0.0.204
    

    And then you can read output one line at a time to create new user files as needed, maybe another script with something along the lines of:

    while read line
    do
        echo "this is a user file" > "$line"
    done < output
    

    (and adjust it to your needs)

    Finally, as long as you understand what’s going on in the above, you can skip the output file altogether and just do this all in a one-liner:

    awk 'BEGIN{FS=OFS="."} {$4=$4+4; print}' input | while read line; do echo "hello world" > "$line"; done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script that runs a program, which generates few .exe files
I have a few directories that contain a lot of files. As some of
I have a few csv files that contain strings with line breaks in them.
In almost all of my projects I have few files that are project wide
I have a few files that were part of an update that were mistakenly
I've got a few files that have been serialized by directly writing C++ struct
I have a folder on my remote server that has a few .png files
I have a few dmp files (generated by different a user) I need to
I have two .CSV files that contain information about the employees from where I
Just wondering about this... I have several separate javascript files, that all contain code

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.