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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-15-2010, 11:06 PM
|
#1
|
|
Member
Registered: Jul 2009
Posts: 41
Rep:
|
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.
|
|
|
|
03-15-2010, 11:31 PM
|
#2
|
|
Senior Member
Registered: Jan 2010
Posts: 1,604
|
Quote:
Originally Posted by quanba
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
|
|
|
|
03-16-2010, 12:00 AM
|
#3
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
Quote:
Originally Posted by quanba
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.
|
|
|
|
03-18-2010, 02:38 PM
|
#4
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
And does this work for you? Some feedback would be appreciated...
|
|
|
|
03-28-2010, 01:19 PM
|
#5
|
|
Member
Registered: Jul 2009
Posts: 41
Original Poster
Rep:
|
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)?
|
|
|
|
03-28-2010, 05:25 PM
|
#6
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:24 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|