Operating System - HP-UX
1829118 Members
2059 Online
109986 Solutions
New Discussion

How to redirect output from a command ??!!!!!!!!!!!

 
Tamer Shaalan
Regular Advisor

How to redirect output from a command ??!!!!!!!!!!!

Hii all professionals...,
I have a certain application command, which when run, collects huge amount of data from a database. I redirect the gained data(in text format) to an ordinary file. but the trick is when this command runs, it prints in the shell some messages ( such as % of progress, number of collected database entries, and so on ), the question is HOW TO REDIRECT THESE MESSAGES to another file other than the file contains data itself ??
Thanx for your interest
Success is a journey, not a destination
9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: How to redirect output from a command ??!!!!!!!!!!!

command >> /tmp/newfile

redirects command output to append /tmp/newfile

command 2>&1 | mailx -s "Subject" someone@aol.com

redirects output to background and then email

The tee command splits output between two files.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Tamer Shaalan
Regular Advisor

Re: How to redirect output from a command ??!!!!!!!!!!!

Dear SEP,
thank you first for your fast responce.
really it is :
command > /usr/file1
file1 now contains database entries.
while it is being run, interactive messages are printed in shell.
HOW TO GET THESE MESSAGES in a SEPARATE file ????
if used tee, i will get the database entries again , not messages !!!!!
Tamer
Success is a journey, not a destination
Rodney Hills
Honored Contributor

Re: How to redirect output from a command ??!!!!!!!!!!!

If the application writes these messages to STDERR, then you can redirect it to /dev/null. example-

command 2>/dev/null >/yourfile

If that is not the case you will need to filter out those lines through sed,awk, or perl. example-

command | sed '/^%/d' >/yourfile

HTH

-- Rod Hills
There be dragons...
Steve Steel
Honored Contributor

Re: How to redirect output from a command ??!!!!!!!!!!!

Hi

If the rogram prints on standard output and the messages as well then forget it

They will go to the same place

If the messages are on standard error
command > /usr/file1 2>otherfile


Only other thing I can think of if both on standard output

command|while read line
do
echo $line|grep -v "%" >> /usr/file1
echo $line |grep "%" >> /usr/file2
done

You will need to extend the greps for all the fields you wnat to move

Steve Steel




If you want truly to understand something, try to change it. (Kurt Lewin)
Michael Schulte zur Sur
Honored Contributor

Re: How to redirect output from a command ??!!!!!!!!!!!

Hi,

what database are we talking about?
If it is an oracle script, you can influence, what oracle prints.
Is it a compiled command or do you happen to
have the script for it?
Otherwise, as stated, it is getting nasty.
Perhaps the easiest way would be to filter the data rows with grep, if they have a common structure.

greetings,

Michael
Peter Nikitka
Honored Contributor

Re: How to redirect output from a command ??!!!!!!!!!!!

Hi,
I'm quite sure, that the status messages are written to stderr. So lets collect the remarks you got till now and try

command 2>&1 >/usr/file1 | tee /tmp/errorlog

to see that status messages AND put it to a file.

For the simple redirct use:
command >/usr/file1 2>/tmp/errorlog

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Tamer Shaalan
Regular Advisor

Re: How to redirect output from a command ??!!!!!!!!!!!

Many Thanks for everyone who interested in replying to me.
I dicovered it is stdrerr and easily separated by " 2> " .I really gained more experience from all your replies.
Again, Thanks a million for all of you !!

Tamer.
Success is a journey, not a destination
Michael Schulte zur Sur
Honored Contributor

Re: How to redirect output from a command ??!!!!!!!!!!!

Tamer,

that's what this place is for. ;-)

greetings,

Michael

ps. have you already read this?
http://forums1.itrc.hp.com/service/forums/helptips.do?#28

Shaikh Imran
Honored Contributor

Re: How to redirect output from a command ??!!!!!!!!!!!

Hi,
To redirect the output to a file
#command > filename
To append the output to a file
#command >> filename


Regards,


I'll sleep when i am dead.