For Programmers: Free Programming Magazines  


Home > Archive > AWK > February 2005 > print $0 > out.txt









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 print $0 > out.txt
danielyeap

2005-02-03, 3:55 am

I am new to AWK. I found that when I were to output something to a
file, I need to enclose the filename with double quotes like:

print $0 > "out.txt"

Can anyone explain why this is needed?

According to the GAWK manual:
The file name output-file can be any expression. Its value is changed
to a string and then used as a file name.

Thanks.
Jürgen Kahrs

2005-02-03, 8:55 am

danielyeap wrote:
> I am new to AWK. I found that when I were to output something to a
> file, I need to enclose the filename with double quotes like:
>
> print $0 > "out.txt"
>
> Can anyone explain why this is needed?


If there were no double quotes, then out.txt
would be taken to be the name of a variable.
This variable could contain the name of the
file. If it does, there everything's fine.

> According to the GAWK manual:
> The file name output-file can be any expression. Its value is changed
> to a string and then used as a file name.


Yes, there is no contradiction between the
manual and your observation. You need to
initialize the variable out.txt with the
name of the file you want to write to.
Aharon Robbins

2005-02-03, 8:55 am

In article <36e7moF50ucdtU1@individual.net>,
Jürgen Kahrs <Juergen.KahrsDELETETHIS@vr-web.de> wrote:
>danielyeap wrote:
>
>If there were no double quotes, then out.txt
>would be taken to be the name of a variable.
>This variable could contain the name of the
>file. If it does, there everything's fine.


Except that variables in awk can't have periods in their names... :-)
--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd. arnold AT skeeve DOT com
P.O. Box 354 Home Phone: +972 8 979-0381 Fax: +1 206 350 8765
Nof Ayalon Cell Phone: +972 50 729-7545
D.N. Shimshon 99785 ISRAEL
Jürgen Kahrs

2005-02-03, 8:55 am

Aharon Robbins wrote:

>
>
> Except that variables in awk can't have periods in their names... :-)


Yes, I should have tested first.
I usually take the _ in such cases.
Sponsored Links







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

Copyright 2008 codecomments.com