For Programmers: Free Programming Magazines  


Home > Archive > AWK > March 2008 > Forced output on screen









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Forced output on screen
Ben

2008-03-12, 7:58 am

Hi all,

I 'd like to know how to send an output in the Terminal.

for example :
$ awk -f example.awk toto.dat > OUT.dat

there is example. awk

BEGIN {
i = 0
}

{
print $0
i++
}

END {
print "You wrote " i " lines" > terminal
}


What is the command for replacing terminal, because I don't want my
last sentence to be written in OUT.dat but in the screen, to inform
the user.

Thanks.
Kenny McCormack

2008-03-12, 7:58 am

In article <a9ac3d21-ba1d-4b63-a141-2a0c219eb02a@c33g2000hsd.googlegroups.com>,
Ben <benoit.bardet@gmail.com> wrote:
>Hi all,
>
>I 'd like to know how to send an output in the Terminal.
>
>for example :
>$ awk -f example.awk toto.dat > OUT.dat


Assuming Unix, you can use /dev/tty:

END {
print "You wrote " i " lines" > "/dev/tty"
}

>What is the command for replacing terminal, because I don't want my
>last sentence to be written in OUT.dat but in the screen, to inform
>the user.
>
>Thanks.


Note: You could also use standard error - there are pluses and minuses
to that.

Joel Reicher

2008-03-12, 7:58 am

Ben <benoit.bardet@gmail.com> writes:

> I 'd like to know how to send an output in the Terminal.
>
> for example :
> $ awk -f example.awk toto.dat > OUT.dat


Why not specify OUT.dat as an argument to the awk script and leave
standard out free?

Cheers,

- Joel
Ed Morton

2008-03-12, 7:58 am



On 3/12/2008 4:29 AM, Ben wrote:
> Hi all,
>
> I 'd like to know how to send an output in the Terminal.
>
> for example :
> $ awk -f example.awk toto.dat > OUT.dat
>
> there is example. awk
>
> BEGIN {
> i = 0
> }


You don't need the BEGIN

> {
> print $0


You don't need the $0

> i++
> }
>
> END {
> print "You wrote " i " lines" > terminal
> }
>
>
> What is the command for replacing terminal, because I don't want my
> last sentence to be written in OUT.dat but in the screen, to inform
> the user.
>
> Thanks.


I think what you really want is that final print to go to stderr insted of
stdout. If you're on UNIX that'd be:

{ print; i++ }
END { print "You wrote " i " lines" | "cat >&2" }

Regards,

Ed.

Ben

2008-03-12, 7:58 am

On 12 mar, 10:56, Joel Reicher <j...@panacea.null.org> wrote:
> Ben <benoit.bar...@gmail.com> writes:
>
>
> Why not specify OUT.dat as an argument to the awk script and leave
> standard out free?
>
> Cheers,
>
> =A0 =A0 =A0 =A0 - Joel


How do you send arguments to the script?

Because my own script will be used for severals differents files.
Ben

2008-03-12, 7:58 am


>
> Assuming Unix, you can use /dev/tty:
>
> END {
> =A0 =A0 print "You wrote " i " lines" > "/dev/tty"
>
> }


This works very well.

Thanks!
Ben

2008-03-12, 7:58 am


>
> I think what you really want is that final print to go to stderr insted of
> stdout. If you're on UNIX that'd be:
>
> { print; i++ }
> END { print "You wrote " i " lines" | "cat >&2" }
>



This work very well too.

thank you very much for your advises.
Ed Morton

2008-03-12, 7:58 am



On 3/12/2008 7:39 AM, Ben wrote:
> On 12 mar, 10:56, Joel Reicher <j...@panacea.null.org> wrote:
>
>
>
> How do you send arguments to the script?
>
> Because my own script will be used for severals differents files.


{ print > file1 ; i++ }
END { print "You wrote " i " lines" }

$ awk -v file1="OUT.dat" -f example.awk toto.dat

Ed.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com