Operating System - HP-UX
1838374 Members
2882 Online
110125 Solutions
New Discussion

Redirecting output to a file and terminal

 
SOLVED
Go to solution
Bala_4
Occasional Advisor

Redirecting output to a file and terminal

Hi All

I would like to redirect the output to the terminal and a file and the error to the error file. This is what I was trying. But the output is never displayed on the screen.

echo "abcd" > aa 2>&1

I want simultaneously the output to be stored in the file and displayed on the terminal.
I am using ksh

Thanks in advance
Bala

6 REPLIES 6
Enbin Hu
Advisor
Solution

Re: Redirecting output to a file and terminal

Bala:

Try the following:

# echo "abcd" | tee -a out_file 2>&1

-EH
Philip Chan_1
Respected Contributor

Re: Redirecting output to a file and terminal

Bala,

You could try the "script" command which would direct all your terminal output to a file without hiding it.

eg.

script outfile.txt

script off

cat outfile.txt


Rgds,
Philip
Madanagopalan S
Frequent Advisor

Re: Redirecting output to a file and terminal

try this:

echo "abcd" | tee aa 2>&1
let Start to create peaceful and happy world
Thomas Schler_1
Trusted Contributor

Re: Redirecting output to a file and terminal

Hi Bala,

I didn't test what the other authors proposed to do. Here is what I found how to get what you want:

(date;date -x) 2> buf2 | tee buf

'buf2' contains stderr while stdout appears on the terminal and is written to 'buf'. See the man page of tee for some options.

Thomas
no users -- no problems
Vincenzo Restuccia
Honored Contributor

Re: Redirecting output to a file and terminal

In echo "abcd" > aa 2>&1 you replace ">" with
|tee -a (-a for append).You can see man tee.


f. halili
Trusted Contributor

Re: Redirecting output to a file and terminal

try this:

===============
$ echo err | tee -a errfile 2>&1
err
$ echo err2 | tee -a errfile 2>&1
err2
$ cat errfile
err
err2
$
===========
- fnhalili
derekh