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

  • Home
  • SEARCH
  • 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 3851836
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:13:27+00:00 2026-05-19T17:13:27+00:00

I need a script that can write text to an exsisting file starting on

  • 0

I need a script that can write text to an exsisting file starting on line 10. It is a blank line so it wont be a find / replace. Would like preferably it to be in bash, but anything that the terminal can interpret will work just fine.

RE-EDITED:

Sorry but still having a bit of a problem after I tested… Think it has something to do with what I want write to a file. Maybe this will make it easier..

  3 c
  4 d
  5 e
  6 f
  7 g
  8 h
  9 i
 10      zone "$zone" in {
 12          type master;
 13          file "/etc/bind/db.$zone";
 14   };
 15 k
 16 l
 17 m

Thanks in Advance,
Joe

  • 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-05-19T17:13:28+00:00Added an answer on May 19, 2026 at 5:13 pm

    Using sed:

    sed -i -e '10a\
    new stuff' file
    

    Using bash:

    IFS=$'\n'
    i=0
    while read -r line; do
        i=$((i+1))
        if test $i -eq 10; then
            echo "new stuff"
        else
            echo "$line"
        fi
    done <file >file.tmp
    mv file.tmp file
    

    Note that I’m not really sure if you mean insert at line 10 or at line 11, so double check the places I wrote 10 above. You might want 9 for the sed command or 11 for the bash version.

    In perl, you can use the $NR variable.

    open FILEHANDLE, "<file";
    while (<FILEHANDLE>) {
        if ($NR == 10) {
            # do something
        }
    }
    

    And in awk, it’s NR.

    awk 'NR != 10 { print }
    NR == 10 { print "Something else" }' file
    

    But note that you can find and replace a blank line, e.g.

    sed -i -e 's/^$/replacement text/' file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to set a system environment variable from a Bash script that would
I'm writing a script that will fold, sort and count text in a file.
I need to a script that will pull up the Task Manager in Vista
I need to create a script that automatically setup a ssh tunnel. I think
I have a script that successfully encrypts a credit card. I need it to
I'm building a fairly simple PHP script that will need to send some emails
I'm creating an installation script for an application that I'm developing and need to
I am trying to write a PHP script that uses the pdftk app to
I need to write a script to do the following: Monitor a queuing system,
I've wrote a python script that need to pass millions of items to a

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.