how print output to screen and output file 
Author Message
 how print output to screen and output file

Hello someone,

I've been searching doc's but to no avail.  As my awk script is running on
my MS machine, the boss wants a little simple status character to show up on
the screen so he knows something is happening.

How do I print a character to the screen when the output of the program is
getting piped to an out file?

I call my program like this:

awk e.awk  in.txt > out.txt

My script (e.awk) , which removes some junk from a file, looks like this:

 BEGIN {
 FS = "|"

Quote:
}

{gsub("[\001-\031]+","",$0);}
{gsub(/\"/,"\'",$0);}
{gsub(/[ ][ ]+/," ",$0);}
{print $0;}


Tue, 30 Sep 2003 07:23:31 GMT  
 how print output to screen and output file

Quote:

>Hello someone,

>I've been searching doc's but to no avail.  As my awk script is running on
>my MS machine, the boss wants a little simple status character to show up
on
>the screen so he knows something is happening.

>How do I print a character to the screen when the output of the program is
>getting piped to an out file?

printf "*" > "con"

In Unix you would do the same thing by printing to "/dev/tty".



Tue, 30 Sep 2003 08:46:25 GMT  
 how print output to screen and output file
How about
awk e.awk in.txt | tee out.txt

Standard out goes to screen and the tee also directs to the file.

Quote:

> Hello someone,

> I've been searching doc's but to no avail.  As my awk script is running on
> my MS machine, the boss wants a little simple status character to show up on
> the screen so he knows something is happening.

> How do I print a character to the screen when the output of the program is
> getting piped to an out file?

> I call my program like this:

> awk e.awk  in.txt > out.txt

> My script (e.awk) , which removes some junk from a file, looks like this:

>  BEGIN {
>  FS = "|"
> }

> {gsub("[\001-\031]+","",$0);}
> {gsub(/\"/,"\'",$0);}
> {gsub(/[ ][ ]+/," ",$0);}
> {print $0;}



Tue, 30 Sep 2003 08:31:56 GMT  
 how print output to screen and output file
Thank you!  That worked perfect!


Quote:


> >Hello someone,

> >I've been searching doc's but to no avail.  As my awk script is running
on
> >my MS machine, the boss wants a little simple status character to show up
> on
> >the screen so he knows something is happening.

> >How do I print a character to the screen when the output of the program
is
> >getting piped to an out file?

> printf "*" > "con"

> In Unix you would do the same thing by printing to "/dev/tty".



Wed, 01 Oct 2003 02:31:17 GMT  
 how print output to screen and output file
Well, I guess this didn't really work, or maybe I didn't understand how to
impliment it correctly.
 I don't actually get the little status characters printed onto the screen
until the program is finished.

If I use "print" instead of "printf" I do, but then the output defeats the
purpose.

Is there a way to printf to the screen, then do a flush so that the output
shows up?

Here is my script so far:

 BEGIN {
 FS = "|"

Quote:
}

{gsub("[\001-\031]+","",$0);}
{gsub(/\"/,"\'",$0);}
{gsub(/[ ][ ]+/," ",$0);}
{print $0;}
NR % 1000 == 0 {printf "*" > "con";}


Quote:


> >Hello someone,

> >I've been searching doc's but to no avail.  As my awk script is running
on
> >my MS machine, the boss wants a little simple status character to show up
> on
> >the screen so he knows something is happening.

> >How do I print a character to the screen when the output of the program
is
> >getting piped to an out file?

> printf "*" > "con"

> In Unix you would do the same thing by printing to "/dev/tty".



Wed, 01 Oct 2003 07:45:00 GMT  
 how print output to screen and output file
I guess I don't have "tee" in my Microsoft dos or windows operating system
or path.  Where would I get that?


Quote:
> How about
> awk e.awk in.txt | tee out.txt

> Standard out goes to screen and the tee also directs to the file.


> > Hello someone,

> > I've been searching doc's but to no avail.  As my awk script is running
on
> > my MS machine, the boss wants a little simple status character to show
up on
> > the screen so he knows something is happening.

> > How do I print a character to the screen when the output of the program
is
> > getting piped to an out file?

> > I call my program like this:

> > awk e.awk  in.txt > out.txt

> > My script (e.awk) , which removes some junk from a file, looks like
this:

> >  BEGIN {
> >  FS = "|"
> > }

> > {gsub("[\001-\031]+","",$0);}
> > {gsub(/\"/,"\'",$0);}
> > {gsub(/[ ][ ]+/," ",$0);}
> > {print $0;}



Wed, 01 Oct 2003 07:49:13 GMT  
 how print output to screen and output file

Quote:

> Hello someone,

> I've been searching doc's but to no avail.  As my awk script is running on
> my MS machine, the boss wants a little simple status character to show up on
> the screen so he knows something is happening.

> How do I print a character to the screen when the output of the program is
> getting piped to an out file?

> I call my program like this:

> awk e.awk  in.txt > out.txt

> My script (e.awk) , which removes some junk from a file, looks like this:

>  BEGIN {
>  FS = "|"
> }

> {gsub("[\001-\031]+","",$0);}
> {gsub(/\"/,"\'",$0);}
> {gsub(/[ ][ ]+/," ",$0);}
> {print $0;}

chznge your program so that the name of the output file is set to a
variable:

awk e.awk in.txt -v outf=out.txt

Have the printf be print $0 > outf;

Then you can print anything.

Martin Cohen



Wed, 01 Oct 2003 10:32:27 GMT  
 how print output to screen and output file

Quote:
> I guess I don't have "tee" in my Microsoft dos or windows operating system
> or path.  Where would I get that?

www.cygwin.com provides most of the GNU tools for Win32.

-Ed

--
How many beans make five?                         |u98ejr

                                                  |ecs.ox.ac.uk



Wed, 01 Oct 2003 19:55:26 GMT  
 how print output to screen and output file

Quote:

>I guess I don't have "tee" in my Microsoft dos or windows operating system
>or path.  Where would I get that?

I'm not sure if that would help you.  "tee" under DOS or Windows would
use Microsoft's fake pipes ( "a | b" is interpreted as "store a's output
in a temp file, then execute b using temp file for input" ).  Maybe you
could use printf "*" > "con"; close("con")


Thu, 02 Oct 2003 07:17:08 GMT  
 how print output to screen and output file
On Fri, 13 Apr 2001 17:45:00 -0600, "burnt_umber"

Quote:

>NR % 1000 == 0 {printf "*" > "con";}

If you have gawk you can try to use the
special device /dev/stderr:

<PRE>
BEGIN{
        screen = "/dev/stderr"
        [other statements]

Quote:
}

(NR % 1000) == 0 {
        printf(".") >screen
        fflush(screen)
        next
Quote:
}

END{
        printf("\nDone.\n")
        fflush(screen)
        close(screen)
Quote:
}

</PRE>

It works for me, even without fflush() ...

Have fun...

--
  (  Kees Nuyt; Rotterdam; Netherlands

c[_] Disclaimer: Any opinions etc. are mine, not necessarily my employer's.



Thu, 02 Oct 2003 17:25:02 GMT  
 how print output to screen and output file

Quote:

> Well, I guess this didn't really work, or maybe I didn't understand how to
> impliment it correctly.
>  I don't actually get the little status characters printed onto the screen
> until the program is finished.
> If I use "print" instead of "printf" I do, but then the output defeats the
> purpose.
> Is there a way to printf to the screen, then do a flush so that the output
> shows up?

Try this:
 ...
 printf("whatever\r") > "/dev/stderr"
... so that "whatever" gets overwritten on the same row again and
again due to the carriage-return behaviour inside a DOS box.
I sometimes use this trick to show a counter of items processed
so far. Another possibility is to use a visual flip-flop:
printf("%s\r", ((NR % 2) ? "\\" : "/")) > "/dev/stderr"

And then add this in the END{} section:
 ...
 printf("\n") > "/dev/stderr"
... so that next output gets ouput where it should.

--
  All true believers shall break their eggs at the convenient end.



Sun, 05 Oct 2003 00:53:30 GMT  
 how print output to screen and output file


...
Quote:
> so far. Another possibility is to use a visual flip-flop:
> printf("%s\r", ((NR % 2) ? "\\" : "/")) > "/dev/stderr"

...

Embellish:

tictoc = "|/-\"
printf("%s\r", substr(tictoc, (NR % 4) + 1, 1))



Sun, 05 Oct 2003 04:43:30 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Printing cut off, output on screen

2. Monitoring the output of the background expect script on the screen and printing it

3. Outputting info from awk and using the info to name the awk output file

4. PRINT PREVIEWER FREEWARE - FormView - Views HP PCL Print Output / Prints PCL to ANY WINDOWS PRINTER

5. writing output listing onto screen (or not) and onto file

6. Printing output corrupts dbf-files

7. printing output files

8. printing ascii fortran output file on apple laser writer

9. Summer '87 Print Output To Print Manager??

10. Create polymorhpic output for I32 input (select output type)

11. rxvt + python problem: script output buffered and interactive output missing

12. HOW TO CAPTURE AN OUTPUT LINE OF A VHDL OUTPUT IN TCL

 

 
Powered by phpBB® Forum Software