| Author |
Forced output on screen
|
|
|
| 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.
| |
|
| 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.
| |
|
|
>
> Assuming Unix, you can use /dev/tty:
>
> END {
> =A0 =A0 print "You wrote " i " lines" > "/dev/tty"
>
> }
This works very well.
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" }
>
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.
|
|
|
|