[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
processing data from stdin
From: |
Mike Miller |
Subject: |
processing data from stdin |
Date: |
Tue, 8 Jun 2004 19:10:12 -0500 (CDT) |
Just thought I'd share something. I was going to submit a question, but
then I figured out the answer on my own, so I'll just submit an answer.
;-)
I have a process that sends a space-delimited matrix to stdout. I want
octave to grab that matrix, do some operations on it, and send output to
stdout. Here is an example process that produces an N-by-3 matrix.
egrep -h '^[0-9]' file*.txt | gawk '{print $1" "$2" "$3}'
I want to perform an operation such as "mean" on that matrix. I'm using
tcsh shell and I came up with this solution:
( echo 'X= [' ; \
egrep -h '^[0-9]' file*.txt | gawk '{print $1" "$2" "$3}' ; \
echo '];' ; echo 'disp(mean(X))' ) | octave -q
It works from the command line, or in a script. The initial and final
parentheses hold stdout in a subshell so that commands separated by
semi-colons produce only a single stdout. Without the "octave -q" on the
end, you would see something like this:
X= [
1 1 1
1 0 1
];
disp(mean(X))
That is piped to Octave and a single row vector is sent by Octave to
stdout. It's pretty neat, thanks to Octave!
Mike
--
Michael B. Miller, Ph.D.
Assistant Professor
Division of Epidemiology
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
-------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- processing data from stdin,
Mike Miller <=