Sponsored Content
Full Discussion: Terminal Output to a File ??
Top Forums UNIX for Advanced & Expert Users Terminal Output to a File ?? Post 302162277 by varungupta on Monday 28th of January 2008 02:24:18 PM
Old 01-28-2008
Computer

Quote:
Originally Posted by KittyWu
The standard way of redirecting the output of a command into a file is to use the 'tee' command:

# Starts 'my_command' command and duplicates
# the outputs from the standard and error devices
# into the 'my_log.txt' log file
my_command 2>&1 | tee my_log.txt

Hope it helps,
C.
Hey,

Thanks man...I got it.

====================================================
Examples
1 To view and save the output from a command at the same time:
Code:
lint program.c | tee program.lint

This displays the standard output of the command lint program.c at the workstation, and at the same time saves a copy of it in the file program.lint. If a file
named program.lint already exists, it is deleted and replaced.
2 To view and save the output from a command to an existing file: lint program.c | tee -a program.lint

This displays the standard output of the lint program.c command at the workstation and at the same time appends a copy of it to the end of the program.lint file.
If the program.lint file does not exist, it is created.


====================================================

Thanks,
Varun.Smilie

Last edited by Yogesh Sawant; 05-26-2010 at 03:06 AM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Output to terminal and file at the same time

Hi all The makefile of a large project produces hundreds of lines of output, which I can't look at any more when the build is finished. If I simply redirect the output to a file, I can't see the progress of the building process... Is there a possibility to redirect the output to a file and at... (1 Reply)
Discussion started by: Charlie
1 Replies

2. Programming

output to terminal

How can I write to another user's pseudo tty, but not to its current prompt position (as in open("/dev/pts007", ...) followed by write() ). Instead I would like to write to the top center of the screen using color red, for example. Like curses, but from another console. (6 Replies)
Discussion started by: andreis
6 Replies

3. Solaris

terminal output - save to file?

I have a window open on my ultra 10 - a terminal window connecting to a server. Is there any way I can log all output to this window to a log file on my ultra 10 ? (2 Replies)
Discussion started by: frustrated1
2 Replies

4. Solaris

how to redirect my output in a new terminal

Hi all, i type a command along with dtterm what i would like to have is that the output of the command to be shown in the new terminal . Any Idea on how to acheive this? (0 Replies)
Discussion started by: Sayantan
0 Replies

5. UNIX Desktop Questions & Answers

Output terminal sessions to screen and log file

I would like to use a terminal session to ssh to switches and routers. I need to capture data while logged into switches to a file I can email for troubleshooting. I use termial to log into Cisco switch, run the sh tech command, and then sent the output to cisco. Is there a way to run a... (4 Replies)
Discussion started by: tdelliott
4 Replies

6. Shell Programming and Scripting

Truncate terminal output

Hello Using BASH under Ubuntu 10.4 lts + XMonad My script is almost perfect but i'm stuck at the last hurdle: I need a sort of modified 'echo' which truncates its output to the width of the terminal I can find the terminal's width with 'stty size' but i dont know how to then convert input... (2 Replies)
Discussion started by: scyptnex
2 Replies

7. Shell Programming and Scripting

how to Redirect the output of telnet command on a terminal to a file ?

(/home/user1)-> more script.sh #!/bin/ksh ( echo open devicename sleep 3; echo user; sleep 2; echo password; sleep 2; echo "/info/dump"; ---------> This needs to redirect to a file .Can be number of pages sleep 2; echo "exit" ) | telnet Please use code tags next time for... (2 Replies)
Discussion started by: necro98
2 Replies

8. UNIX for Dummies Questions & Answers

Strange behaviour when output to terminal vs file (awk)

Hi all ! I noticed something very weird. I have a large pipe delimited file (20 fields/3,000 records) that looks like that: AAA|BBB|11111|22222|...|($NF of record 1) CCC|DDD|33333|44444|...|($NF of record 2) CCC|DDD|55555|66666|...|($NF of record 3) For the lines with same 1st and 2nd... (3 Replies)
Discussion started by: beca123456
3 Replies

9. Shell Programming and Scripting

Printing Terminal Output to a Error File

I am having a bash script which is basically invoking a python program to validate the Source Query results against the target query results. I am placing all the queries in a .sql file. I want to write to a Error log file incase if the syntax is wrong or if the column is not present in the... (4 Replies)
Discussion started by: ronitreddy
4 Replies

10. Shell Programming and Scripting

Print Terminal Output Exactly how it Appears in the Terminal to a New Text File

Hello All, I have a text file containing output from a command that contains lots of escape/control characters that when viewed using vi or view, looks like jibberish. But when viewed using the cat command the output is formatted properly. Is there any way to take the output from the cat... (7 Replies)
Discussion started by: mrm5102
7 Replies
tee(1)							      General Commands Manual							    tee(1)

NAME
tee - Displays the output of a program and copies it into a file SYNOPSIS
tee [-ai] file... STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: tee: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Adds the output to the end of file instead of writing over it. Ignores the SIGINT signal. OPERANDS
Standard input is stored into, or appended to, the file specified. [Tru64 UNIX] The tee command can accept up to 20 file arguments. DESCRIPTION
The tee command reads standard input and writes to both standard output, and each specified file. The tee command is useful when you wish to view program output as it is displayed, and also want to save it in a file. The tee command does not buffer output, so you may wish to pipe the output of tee to more if more than one full screen of data is anticipated. NOTES
If a write to any file fails, the exit status of tee will be non-zero. Writes to all other specified files may be successful, and opera- tion will continue until standard input is exhausted. EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. EXAMPLES
To view and save the output from a command at the same time, enter: lint program.c | tee program.lint This displays the standard output of the command lint program.c at the terminal, and at the same time saves a copy of it in the file program.lint. If program.lint already exists, it is deleted and replaced. To display and append to a file, enter: lint program.c | tee -a program.lint This displays the standard output of lint program.c at the terminal and at the same time appends a copy of it to the end of pro- gram.lint. If the file program.lint does not exist, it is created. ENVIRONMENT VARIABLES
The following environment variables affect the execution of tee: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the for- mat and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: cat(1), echo(1), script(1) Standards: standards(5) tee(1)
All times are GMT -4. The time now is 07:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy