| Janis Papanagnou 2005-11-23, 5:54 pm |
| Meghavvarnam wrote:
> Ed Morton wrote:
>
>
>
> Apologies for asking some basic questions.
>
> I have some doubts about the above gawk script. Request your time for
> clarifications.
>
> 1. There are two variables - string and strings. I dont know what value
> will the variable 'string' have when it iterates for the very first
> time. Is it by default assigned to 0 ?
All variables are either "" (empty string) or 0 (numeric zero) when
you access them the first time.
> 2. I simply pasted this script in a file and gave execute permission
> and then executed it from the command line. Have I done it right ? Am
> in doubt here because I was thinking if I should use gawk -f <script
> file name>
> Did I run your script in the right way at all ?
On Unix you can define as first line in your script
#!/bin/awk -f
(or whereever your awk is installed), or you can call the awk interpreter
explicitly with the file
awk -f file_with_your_awk_program
or with the program (not recommended for programs of non-trivial size)
awk '...awk-statements...'
> I have modified the if in the for loop to this:
> if (index($0,">"string"<") || index($0,"\""string"\"") ||
> index($0,">"string"\n" ) {
>
> to include strings within double quotes (") and strings that have ">"
> before them and end with a new line. Please correct me if am wrong
> here.
>
> Here is what happened when I ran the script :
> gawk: cmd. line:2: { for (string in strings}
> gawk: cmd. line:2: ^ parse error
It's like in other computer laguages, the brackets must match
{ for (string in strings)
> [big snip]
Janis
|