Problem running awk script in Debian 6.0.2

Hello to all,

May be some expert could help me.

I have the below awk script that works correctly in Cygwin:

awk -F\" 'FNR==NR && FNR>1 {gsub(",","",$5); N[$2]=$5;next}
$10 in N && FNR>1 {
Y[$10]=$8
Z[$10]=(N[$10]==$8)?"Yes:"No";
}
END{
for(k in N) {print k,Y[k],N[k],Z[k]?Z[k]:"Not_Found"}
}' file2 file1

But when I try to run it in Debian version shown below, the script doesn't print the correct output or Segmentation fault appears:

~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 6.0.2 (squeeze)
Release:        6.0.2
Codename:       squeeze

When I sen man awk I get the description of mawk command.

What could be the problem here and what should I do to fix it?

Many thanks in advance for your help.

You have error here:

Z[$10]=(N[$10]==$8)?"Yes:"No";

should be:

Z[$10]=(N[$10]==$8)?"Yes":"No";

Hello bartus11,

Thanks for your answer.

I've fixed that part, but is no that, still fails. Doesn't print the correct output and even If I change to mawk :(.

If I use the same script in cygwin works just perfect.

I don't know if Debian needed a different syntax or something.

Do you have "gawk" available there?

Hello bartus,

If I enter man awk or man nawk I get the description of mawk. But if I enter man gawk I receive "No manual entry for gawk".

Don't run "man gawk", just "gawk" to see if that version is installed.

bartus, I get this

$ gawk
-bash: gawk: command not found

---------- Post updated at 05:31 PM ---------- Previous update was at 05:24 PM ----------

If I go to:

/usr/bin

I see this:

lrwxrwxrwx 1 root   root         21 Dec 12  2008 awk -> /etc/alternatives/awk

try putting the script in a file and run it with 'awk -f myScriptFile myInputFile'.
make sure there are not ^M-s and/or other crumbs....

any other awk-s under /usr/bin?
ls /usr/bin/*awk*
Or under /usr/local/bin ?

Hello vgersh99,

Thank you for the help.

There is no other awk in /usr/bin/ and there is none in /usr/local/bin.

and what part of the code must go in a file? I've put this part in a file

-F\" 'FNR==NR && FNR>1 {gsub(",","",$5); N[$2]=$5;next}
$10 in N && FNR>1 {
Y[$10]=$8
Z[$10]=(N[$10]==$8)?"Yes:"No";
}
END{
for(k in N) {print k,Y[k],N[k],Z[k]?Z[k]:"Not_Found"}
}' file2 file1

and doesn't work.

If I put the -F\" outside of the file and I do this:

awk -f -F\" script.sh

fails too.

I don't know how should be the correct way to put it within a file. Please help me.

Thanks again

awk -F\" -f op.awk file2 file1
op.awk:

FNR==NR && FNR>1 {
    gsub(",","",$5)
    N[$2]=$5;next
} 
$10 in N && FNR>1 {
    Y[$10]=$8
    Z[$10]=(N[$10]==$8)?"Yes":"No"
} 

END { 
   for(k in N) 
      print k,Y[k],N[k],Z[k]?Z[k]:"Not_Found"
}

hello vgersh9,

The result using:

awk -F\" -f op.awk file2 file1

is the same as running the awk script in the other way

. script file2 file1

Only prints correctly the first 2 lines. For the rest of lines, is not printing column1 nor column2,
it seems a problem with the arrays, like the arrays don't have or don't store any value.

But again, the script works in Cygwin just perfect.

Thanks for any help.