1.

Solve : How do we use gawk.exe??

Answer»
I got the following errors using gawk.exe. MAY we run gawk.exe from the command line?

C:\batch>"C:\Program Files\GnuWin32\bin\gawk.exe" -F"|" '{a[$1]=a[$1] FS $2 FS $3 } END {for(i in a){print i,a} }' awkinfile.txt
gawk: '{a[$1]=a[$1]
gawk: ^ INVALID char ''' in expression

C:\batch>type awkinfile.txt
301|AF_ACC_BDL|774;
301|AF_WMG_BDL|6660;
301|AF_REP_BDL|4735;
303|AF_ACC_BDL|1360;
304|AF_ACC_BDL|5092;
305|AF_ACC_BDL|32384;
306|AF_ACC_BDL|80859;
306|AF_REP_BDL|80875;
308|AF_ACC_BDL|1418;
308|AF_WLH_BDL|78273;
308|AF_WSL_BDL|9990;
308|AF_WFL_BDL|9998;


C:\batch>

use double quotes instead of single quotes on win32. Read the gawk manual under Getting Started section 1.1.6.1 Quoting in MS-DOS Batch Files.

CODE: [Select]gawk.exe -F"|" "{a[$1]=a[$1] FS $2 FS $3 } END {for(i in a){print i,a[i]} }" awkinfile.txt
Quote from: ghostdog74 on December 27, 2009, 08:18:09 PM
use double quotes instead of single quotes on win32. Read the gawk manual under Getting Started section 1.1.6.1 Quoting in MS-DOS Batch Files.

Code: [Select]gawk.exe -F"|" "{a[$1]=a[$1] FS $2 FS $3 } END {for(i in a){print i,a} }" awkinfile.txt



C:\batch>"C:\Program Files\GnuWin32\bin\gawk.exe" -F"|" "{a[$1]=a[$1] FS $2 FS $3 } END {for(i in a){print i,a} }" awkinfile.txt

gawk: (FILENAME=awkinfile.txt FNR=13) fatal: ATTEMPT to use array `a' in a scalar context

C:\batch>type awkinfile.txt
301|AF_ACC_BDL|774;
301|AF_WMG_BDL|6660;
301|AF_REP_BDL|4735;
303|AF_ACC_BDL|1360;
304|AF_ACC_BDL|5092;
305|AF_ACC_BDL|32384;
306|AF_ACC_BDL|80859;
306|AF_REP_BDL|80875;
308|AF_ACC_BDL|1418;
308|AF_WLH_BDL|78273;
308|AF_WSL_BDL|9990;
308|AF_WFL_BDL|9998;


C:\batch>I really can't stand you. Did you copy and paste my code properly? if not, type it in correctly on your terminal.!!! Quote from: ghostdog74 on December 27, 2009, 08:46:24 PM
Did you copy and paste my code properly? if not, type it in correctly on your terminal.!

The code does not work and you blame me? We can see the code is the same as was given. I USED copy and paste.

How could we not copy and paste correctly?

Here it is again:


C:\batch>"C:\Program Files\GnuWin32\bin\gawk.exe" -F"|" "{a[$1]=a[$1] FS $2 FS $
3 } END {for(i in a){print i,a} }" awkinfile.txt
gawk: (FILENAME=awkinfile.txt FNR=13) fatal: attempt to use array `a' in a scalar context

What is typed incorrectly?

C:\batch>Quote from: ghostdog74 on December 27, 2009, 08:46:24 PM
Did you copy and paste my code properly? if not, type it in correctly on your terminal.!

I used another awk program* and it worked:
http://www.pement.org/awk/awk1line.txt

C:\batch>"C:\Program Files\GnuWin32\bin\gawk.exe" "{ total = total + NF }; END {
print total}" awkinfile.txt
12

Quote from: ghostdog74 on December 27, 2009, 08:46:24 PM
Did you copy and paste my code properly? If not, type it in correctly on your terminal.

I finally got your "all in one line" gawk to run. Thanks for your help.
Here it is from my machine:

C:\batch>"C:\Program Files\GnuWin32\bin\gawk.exe" -F"|" "{a[$1]=a[$1] FS $2 FS $3}END{for(i in a){ print i,a } }" file
||
301 |AF_ACC_BDL|774;|AF_WMG_BDL|6660;|AF_REP_BDL|4735;
303 |AF_ACC_BDL|1360;
304 |AF_ACC_BDL|5092;
305 |AF_ACC_BDL|32384;
306 |AF_ACC_BDL|80859;|AF_REP_BDL|80875;
308 |AF_ACC_BDL|1418;|AF_WLH_BDL|78273;|AF_WSL_BDL|9990;|AF_WFL_BDL|9998;

C:\batch>

p.s. I used copy and paste
Code: [Select]gawk.exe" -F"|" "{a[$1]=a[$1] FS $2 FS $3}END{for(i in a){ print i,a } }" file
the above will give you error at this part here ---------------------^. it should be
Code: [Select]gawk.exe" -F"|" "{a[$1]=a[$1] FS $2 FS $3}END{for(i in a){ print i,a[i] } }" file

so i really doubt you are doing the right thing.gawk.exe" -F"|" "{a[$1]=a[$1] FS $2 FS $3}END{for(i in a){ print i,a } }" file
[/quote]
So I really doubt you are doing the right thing.
[/quote]

I got the right answer and posted the output. Thanks for your help.

I finally got your "all in one line" gawk to run. Thanks for your help.
Here it is from my machine:

C:\batch>"C:\Program Files\GnuWin32\bin\gawk.exe" -F"|" "{a[$1]=a[$1] FS $2 FS $3}END{for(i in a){ print i,a } }" file
||
301 |AF_ACC_BDL|774;|AF_WMG_BDL|6660;|AF_REP_BDL|4735;
303 |AF_ACC_BDL|1360;
304 |AF_ACC_BDL|5092;
305 |AF_ACC_BDL|32384;
306 |AF_ACC_BDL|80859;|AF_REP_BDL|80875;
308 |AF_ACC_BDL|1418;|AF_WLH_BDL|78273;|AF_WSL_BDL|9990;|AF_WFL_BDL|9998;

I had a long rant here but realized it was just a waste of time.

Quote from: ghostdog74 on December 27, 2009, 08:46:24 PM
I really can't stand you.

We'd be hard pressed to fine somebody who does!Quote from: BC_Programmer on December 29, 2009, 10:26:18 AM
I had a long rant here but realized it was just a waste of time.

We'd be hard pressed to fine somebody who does!

Thanks for the kind words. I'm doing something right.

Sincerely,

Bill Richardson


Discussion

No Comment Found