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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:34:56+00:00 2026-06-08T06:34:56+00:00

Is it possible to write to an excel sheet(any type) from a bash script

  • 0

Is it possible to write to an excel sheet(any type) from a bash script ?

What I am looking for is something along these lines :

sed -e :a -e '$!N; s/\n/ /; ta' file.c > #( first coloumn ,second row of the spread sheet ) 
echo "$cdvar" > #( second coloumn ,third row of the spread sheet ) 

Thank you for your replies and suggestion .

  • 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-08T06:34:59+00:00Added an answer on June 8, 2026 at 6:34 am

    You could write excel by bash, perl, python, .. I think that each program language has its solutions.

    bash

    You could use join or awk, and I think that there are other solutions.

    join

    If you want join to files with same column, look these posts: Bash join command and join in bash like in SAS

    awk

    You could write a csv, but you could rename into xls and then with excel, gnumeric, or other programs, it is recognized like xls.

    ls -R -ltr / | head -50 | awk '{if ($5 >0) print $5,$9}' OFS="," > sample.xls
    

    when you modify xls with excel, gnumeric, or other programs, and save in xls,
    you could not read by bash. So that @Geekasaur recommended perl or python solutions.

    perl

    You could write xls in perl, follow a sample:

    #!/usr/bin/perl
    use Spreadsheet::WriteExcel;
    my $workbook = Spreadsheet::WriteExcel->new("test.xls"); 
    my $worksheet = $workbook->add_worksheet();
    open(FH,"<file") or die "Cannot open file: $!\n";
    my ($x,$y) = (0,0);
    while (<FH>){ 
     chomp;
     @list = split /\s+/,$_;
     foreach my $c (@list){
        $worksheet->write($x, $y++, $c);     
     }
     $x++;$y=0;
    }
    close(FH);
    $workbook->close();
    

    And then you could modify xls with Spreadsheet::ParseExcel package: look How can I modify an existing Excel workbook with Perl? and reading and writing sample [Editor’s note: This link is broken and has been reported to IBM]

    python

    You could write real xls in python, follow a sample:

    #!/usr/local/bin/python
    # Tool to convert CSV files (with configurable delimiter and text wrap
    # character) to Excel spreadsheets.
    import string
    import sys
    import getopt
    import re
    import os
    import os.path
    import csv
    from pyExcelerator import *
    
    def usage():
      """ Display the usage """
      print "Usage:" + sys.argv[0] + " [OPTIONS] csvfile"
      print "OPTIONS:"
      print "--title|-t: If set, the first line is the title line"
      print "--lines|-l n: Split output into files of n lines or less each"
      print "--sep|-s c [def:,] : The character to use for field delimiter"
      print "--output|o : output file name/pattern"
      print "--help|h : print this information"
      sys.exit(2)
    
    def openExcelSheet(outputFileName):
      """ Opens a reference to an Excel WorkBook and Worksheet objects """
      workbook = Workbook()
      worksheet = workbook.add_sheet("Sheet 1")
      return workbook, worksheet
    
    def writeExcelHeader(worksheet, titleCols):
      """ Write the header line into the worksheet """
      cno = 0
      for titleCol in titleCols:
        worksheet.write(0, cno, titleCol)
        cno = cno + 1
    
    def writeExcelRow(worksheet, lno, columns):
      """ Write a non-header row into the worksheet """
      cno = 0
      for column in columns:
        worksheet.write(lno, cno, column)
        cno = cno + 1
    
    def closeExcelSheet(workbook, outputFileName):
      """ Saves the in-memory WorkBook object into the specified file """
      workbook.save(outputFileName)
    
    def getDefaultOutputFileName(inputFileName):
      """ Returns the name of the default output file based on the value
          of the input file. The default output file is always created in
          the current working directory. This can be overriden using the
          -o or --output option to explicitly specify an output file """
      baseName = os.path.basename(inputFileName)
      rootName = os.path.splitext(baseName)[0]
      return string.join([rootName, "xls"], '.')
    
    def renameOutputFile(outputFileName, fno):
      """ Renames the output file name by appending the current file number
          to it """
      dirName, baseName = os.path.split(outputFileName)
      rootName, extName = os.path.splitext(baseName)
      backupFileBaseName = string.join([string.join([rootName, str(fno)], '-'), extName], '')
      backupFileName = os.path.join(dirName, backupFileBaseName)
      try:
        os.rename(outputFileName, backupFileName)
      except OSError:
        print "Error renaming output file:", outputFileName, "to", backupFileName, "...aborting"
        sys.exit(-1)
    
    def validateOpts(opts):
      """ Returns option values specified, or the default if none """
      titlePresent = False
      linesPerFile = -1
      outputFileName = ""
      sepChar = ","
      for option, argval in opts:
        if (option in ("-t", "--title")):
          titlePresent = True
        if (option in ("-l", "--lines")):
          linesPerFile = int(argval)
        if (option in ("-s", "--sep")):
          sepChar = argval
        if (option in ("-o", "--output")):
          outputFileName = argval
        if (option in ("-h", "--help")):
          usage()
      return titlePresent, linesPerFile, sepChar, outputFileName
    
    def main():
      """ This is how we are called """
      try:
        opts,args = getopt.getopt(sys.argv[1:], "tl:s:o:h", ["title", "lines=", "sep=", "output=", "help"])
      except getopt.GetoptError:
        usage()
      if (len(args) != 1):
        usage()
      inputFileName = args[0]
      try:
        inputFile = open(inputFileName, 'r')
      except IOError:
        print "File not found:", inputFileName, "...aborting"
        sys.exit(-1)
      titlePresent, linesPerFile, sepChar, outputFileName = validateOpts(opts)
      if (outputFileName == ""):
        outputFileName = getDefaultOutputFileName(inputFileName)
      workbook, worksheet = openExcelSheet(outputFileName)
      fno = 0
      lno = 0
      titleCols = []
      reader = csv.reader(inputFile, delimiter=sepChar)
      for line in reader:
        if (lno == 0 and titlePresent):
          if (len(titleCols) == 0):
            titleCols = line
          writeExcelHeader(worksheet, titleCols)
        else:
          writeExcelRow(worksheet, lno, line)
        lno = lno + 1
        if (linesPerFile != -1 and lno >= linesPerFile):
          closeExcelSheet(workbook, outputFileName)
          renameOutputFile(outputFileName, fno)
          fno = fno + 1
          lno = 0
          workbook, worksheet = openExcelSheet(outputFileName)
      inputFile.close()
      closeExcelSheet(workbook, outputFileName)
      if (fno > 0):
        renameOutputFile(outputFileName, fno)
    
    if __name__ == "__main__":
      main()
    

    And then you could also convert to csv with this sourceforge project.
    And if you could convert to csv, you could rewrite xls.. modifing the script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to write generic class with one constructor which explicitly defines type
Possible Duplicate: Populate unique values in to VBA array from excel I need to
is that possible to extract out all the data in second sheet from each
Is it possible to write a script that will execute every day in certain
Is it possible to create and write to a (new) excel file using the
I was wondering if it is possible to not attach Excel sheet if it
Is possible to write language agnostic Robotium tests? For example, if you use a
Is it possible to write GLSL ES fragment shaders under iOS that generate multiple
Is it possible to write a method in Scala which returns an object of
Is it possible to write this query in codeigniter active records? $Main_Nav_Query = mysql_query(SELECT

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.