Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Print to STDERR in AWK

13,599 views
Skip to first unread message

Kenneth Brun Nielsen

unread,
May 30, 2008, 6:48:17 AM5/30/08
to
I have a file, that is parsed through AWK. I would like a few run-time
comments to be printed to STDOUT while processing within AWK.

How can I do that?

/Kenneth

Stephane CHAZELAS

unread,
May 30, 2008, 6:52:58 AM5/30/08
to
2008-05-30, 03:48(-07), Kenneth Brun Nielsen:

> I have a file, that is parsed through AWK. I would like a few run-time
> comments to be printed to STDERR while processing within AWK.
[...]

On systems that have /dev/stderr or where awk fakes /dev/stderr,
you can do:

print "foo" > "/dev/stderr"

Otherwise, you can do:

system("echo foo >&2")

or

print "foo" | "cat >&2"

--
Stéphane

pk

unread,
May 30, 2008, 6:46:24 AM5/30/08
to

To STDOUT or STDERR?

With GNU awk (and probably others), to print to stdout, just redirect
to /dev/stdout. To print to stderr, redirect to /dev/stderr.

man awk

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Kenneth Brun Nielsen

unread,
May 30, 2008, 7:04:54 AM5/30/08
to
On May 30, 12:52 pm, Stephane CHAZELAS <stephane_chaze...@yahoo.fr>
wrote:
> 2008-05-30, 03:48(-07)

> I have a file, that is parsed through AWK. I would like a few run-time
> > comments to be printed to STDERR while processing within AWK.
>
> [...]
>
> On systems that have /dev/stderr or where awk fakes /dev/stderr,
> you can do:
>
> print "foo" > "/dev/stderr"

Thanks. Both of you.

/Kenneth

0 new messages