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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:11:23+00:00 2026-05-23T09:11:23+00:00

Is there a way to insert a header at the top of a file?

  • 0

Is there a way to insert a header at the top of a file? I have a script that scans 5 ip addresses then outputs the 5 ip scan results into one Microsoft excel file in csv format. I want to add a header at the top of the page describing what each column displays such as IP, protocol, port and etc. Currently i have this piece of code to do this:

open (FILE, ">>/root/scanned_ip_addresses.csv"); #open excel file
print FILE  "IP,Protocol,Port,State,Service\n"; #Adds header to top of file.

while (<TEXT>) {
...

Unfortunately its not outputting the way I want it to, due to there being five separate scans its outputting a header after each IP scan, instead of just one header. Heres an example of how it outputs:

IP Port Protocol State Service
xx  xx    xxx     xxxx  xxxxx  
IP Port Protocol State Service
xx  xx    xxx     xxxx  xxxxx  
IP Port Protocol State Service
xx  xx    xxx     xxxx  xxxxx  
IP Port Protocol State Service
xx  xx    xxx     xxxx  xxxxx  
IP Port Protocol State Service
xx  xx    xxx     xxxx  xxxxx  

I would like it to print out like this:

IP Port Protocol State Service
xx  xx    xxx     xxxx  xxxxx  
xx  xx    xxx     xxxx  xxxxx 
xx  xx    xxx     xxxx  xxxxx 
xx  xx    xxx     xxxx  xxxxx 
xx  xx    xxx     xxxx  xxxxx 

How can i fix this problem?

  • 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-23T09:11:24+00:00Added an answer on May 23, 2026 at 9:11 am

    I get the impression that you’re running your script multiple times and each time it is run, you append new results to your CSV file. If that’s the case, then all you have to do is check the file size right after your open:

    open (FILE, ">>/root/scanned_ip_addresses.csv");
    if(-s '/root/scanned_ip_addresses.csv' == 0) {
        # No content implies that we just created the file
        # and it needs a header
        print FILE  "IP,Protocol,Port,State,Service\n";
    }
    # And now continue on as usual
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to insert a string in a string constant/variable that contains
Is there a way that I can insert values into a VB.NET Dictionary when
Is there a way to modify the header (say to insert a security /
Is there a way to insert a Table Header View (tableHeaderView) in StoryBoard (like
I have an sql insert script that updates the sql table in the database
Is there any way to insert more than one page header to crystal reports
Is there a way in TCPDF to insert a header on each page? I
I have a csv file in which I am able to insert the header
I have a function that exports a table into a CSV file, then I
Is there any way to insert facebook like into pop image of fancybox?

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.