Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk output to other file descriptors

Status
Not open for further replies.

Daedelus

Technical User
Aug 14, 2002
70
US
Does anyone know a better way to direct awk output to more than one file descriptor than using

print "out" | "cat 1>&2"

for example?

I would nawk, but around here there is no "would" to nawk, and I can't stand around and gawk. It's a very awk-ward situation. I suppose I can always squawk.
 

the statement is:

print WhatYouWant ">fileA";
print WhatYouWant ">fileB";
print WhatYouWant ">fileC";

awk has a limited # of filedescriptors, circa 15 ?
check also the syntax: " or ' ... i don't remember.
------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
print WhatYouWant > "fileA"
print WhatYouWant > "fileB"
print WhatYouWant > "fileC"

Each awk implementaion has a different maximum number of currently open files allowed, except gawk, which is unlimited (it does it by internally closing files as necessary) CaKiwi
 
Okay, that works fine for output to files (at least without the quotes, with them it prints:
"WhatYouWant>fileA"
to standard output.)

But what I really want to do is print status information to the terminal, while I am piping the awk output to another command.
I have tried

print "out" >&2

but awk squawks that this statement cannot be correctly parsed. I was hoping there might be a more elegant solution than the pipe to "cat >&2" one I gave above. Thanks
 
gawk provides the following syntax to write to stderr, but other awks do not, as far as I know.

print "error" > "/dev/stderr"

Your method of piping to cat is only way I know of to do it for other awks. CaKiwi
 
Thanks to you both. I guess just because I wish I could do something doesn't mean I can. And thanks CaKiwi for pointing out that the > has to be outside the quotes. I tried: print "out" >"&2" on a whim. The result was I had to figure out how to remove a file named "&2", since rm &2 will not do it! (rm \&2 works).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top