[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: save -ascii filename variable
From: |
Mike Miller |
Subject: |
Re: save -ascii filename variable |
Date: |
Wed, 9 Mar 2005 11:50:47 -0600 (CST) |
On Wed, 9 Mar 2005, Anderson, John M. wrote:
When I save a variable in ascii format, some header information is
included (e.g., save -ascii fn imageresult):
Created by: ...
Name: ...
Type: ...
Rows: ...
Column: ...
How can I (1) remove the header information in a C program or (2) save a
variable in ascii format w/o the header?
Coincidentally, we were just discussing this very issue. You can't do '2'
yet, but for '1', when you have saved only one variable in the ascii file,
you can run this script:
------------------------begin script on next line----------------------
#!/usr/bin/perl -i -p
# This removes the initial header lines of an octave ascii data file
BEGIN{undef $/} s/(# [^\n]*\n)+ / /
------------------------end script on previous line--------------------
In any collection of text files, it removes all initial consecutive lines
that begin with '# ' (without the quotes) when the following line begins
with a space. You could name the script 'remove_octave_headers', make
sure the path to perl is correct for your system (that is, edit the first
line of the script appropriately), then run it like this to fix all the
Octave ascii output files (all files with extension .out) in the default
directory:
remove_octave_headers *.out
It replaces all of the original .out files with the headerless files. I
am assuming that a line beginning with a space always follows the last
line of the header - I believe that is always true.
Other people have suggested using grep, or whatever, but this perl method
is very convenient because it allows you to replace without the extra step
of making a second file and renaming or deleting. It's the easiest way I
can think of to do it.
Mike
--
Michael B. Miller, Ph.D.
Assistant Professor
Division of Epidemiology and Community Health
and Institute of Human Genetics
University of Minnesota
http://taxa.epi.umn.edu/~mbmiller/
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------