LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-15-2010, 11:06 PM   #1
quanba
Member
 
Registered: Jul 2009
Posts: 41

Rep: Reputation: 15
awk: how can I print out a message to the screen when redirecting the output to file.


Hi there,

I have a problem when using awk:

e.g: awk '{processing text}' File1 > File2

But when I'm processing the File1, I want to print out some messages to the screen (not the File2). How can I do that?

p/s: thanks for your help.
 
Old 03-15-2010, 11:31 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by quanba View Post
Hi there,

I have a problem when using awk:

e.g: awk '{processing text}' File1 > File2

But when I'm processing the File1, I want to print out some messages to the screen (not the File2). How can I do that?

p/s: thanks for your help.
Well, then just do not redirect it to File2.
Code:
awk '{processing text}' File1
If you want to print on screen and redirect to File2 then
Code:
awk '{processing text}' File1 | tee File2
 
Old 03-16-2010, 12:00 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally Posted by quanba View Post
Hi there,

I have a problem when using awk:

e.g: awk '{processing text}' File1 > File2

But when I'm processing the File1, I want to print out some messages to the screen (not the File2). How can I do that?

p/s: thanks for your help.
Code:
awk '{print "processing text: " FILENAME > "/dev/stderr"}' File1 > File2
should work

Last edited by Tinkster; 03-16-2010 at 12:02 AM.
 
Old 03-18-2010, 02:38 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
And does this work for you? Some feedback would be appreciated...
 
Old 03-28-2010, 01:19 PM   #5
quanba
Member
 
Registered: Jul 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks Tinkster, sorry for being overloaded and forgot about this thread. Your solution works greatly. I am wondering if it's unusual if we print out a message to /etc/stderr in case it's not an error (just a result of some action)?
 
Old 03-28-2010, 05:25 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Not sure I quite understand your question; it's not uncommon to print
informational stuff (in other words status messages and the like) out
to stderr. Normally stdout is just for "payload" of a process, stderr
for anything else.


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
redirecting make output to file babu198649 Linux - Newbie 20 09-02-2010 03:30 AM
Redirecting output from screen to console from boot-up ? exceed1 Linux - General 3 11-23-2008 10:26 PM
Redirecting socket output to a file elmafiacs Programming 1 10-15-2005 05:18 AM
redirecting output of compile to a file halfcan Linux - Hardware 1 02-05-2005 10:01 PM
redirecting cpio screen output to file rawii Solaris / OpenSolaris 1 02-11-2004 09:28 AM


All times are GMT -5. The time now is 04:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration