How can I make this awk statement run on Windows?

1

awk '/DoLabelQuery\(self\)/||/QName\[[[[:digit:]][[[:digit:]]]/||/QName\[[[[:digit:]]]/ || /;BUTTON =/ || /endMethod/ || /endmethod/ ||  /add\(/ || /;CODE = /'  HELLO.fsl > x.txt

I know it has to be made into a file and run using awk -f. I just can't seem to get the syntax right. The example above works in Linux in the terminal.

It may look complicated but all I'm looking for is 5-6 examples of text where if found leads to that line being written out to x.txt. The QName name element is just looking for QName[##] or QName[#].

Peter Dixon

Posted 2017-08-15T16:50:01.803

Reputation: 11

What happens when you try running it? Can you give us some sample input to test with? Does it have to be awk? If you just want matched lines to be printed, grep seems like a good tool for the job – Eric Renouf – 2017-08-15T17:06:38.350

Using gawk-3.1.6 for win32 I got your command to work if I just used double quotes instead of single quotes, does that work for you? – Eric Renouf – 2017-08-15T17:22:11.630

Using double quotes didn't give me an error but it yield a result with zero bytes. The input file is a binary form with islands of ASCII that we are trying to target. Kind of hard to give you that. Can you show me any similar Windows awk example where a file is used to supply the awk commands? I can['t seem to find that using Google. – Peter Dixon – 2017-08-15T17:53:23.587

What are you using for awk on Windows? I get a line of output if I do, for example: gawk "/cannot be run in DOS/" awk.exe so that gawk with double quotes can process binary files and find ascii within them – Eric Renouf – 2017-08-15T17:56:27.670

The issue does seem to be related to running on a binary file. If I strip out the control characters the commands seem to work ok, or at least a simplified version of it does. I'm using the most recent version of awk/gawk from http://gnuwin32.sourceforge.net/packages/gawk.htm.

– Peter Dixon – 2017-08-15T18:10:26.927

Decided to go with Window's FINDSTR command. It seems to be less problematic that awk on the Windows platform. It's too bad, because on Linux awk worked perfectly well. Unfortunately this app has to run end to end on Windows. – Peter Dixon – 2017-08-15T18:33:45.730

Answers

1

When I tried to run your command at first I got the error:

awk: '/DoLabelQuery\(self\)/
awk: ^ invalid char ''' in expression
'/QName\[[[[:digit:]][[[:digit:]]]/' is not recognized as an internal or external command,
operable program or batch file.
'/QName\[[[[:digit:]]]/' is not recognized as an internal or external command,
operable program or batch file.
'/' is not recognized as an internal or external command,
operable program or batch file.
'/endMethod/' is not recognized as an internal or external command,
operable program or batch file.
'/endmethod/' is not recognized as an internal or external command,
operable program or batch file.
'/add\' is not recognized as an internal or external command,
operable program or batch file.
'/' is not recognized as an internal or external command,
operable program or batch file.

which makes it seem that all the parts of the awk script are being parsed as separate words and many of them are then being processed as though they are commands after ||. This is because, as this SO question shows single quotes aren't really quotes in Windows cmd shell, as they are in (most?) linux shells. cmd uses only double quotes, which fortunately works fine for this command it seems, so the solution here is to use:

awk "/DoLabelQuery\(self\)/||/QName\[[[[:digit:]][[[:digit:]]]/||/QName\[[[[:digit:]]]/ || /;BUTTON =/ || /endMethod/ || /endmethod/ ||  /add\(/ || /;CODE = /"  HELLO.fsl > x.txt

though I would expect putting the commands into a file and using it that way should work as well.

Eric Renouf

Posted 2017-08-15T16:50:01.803

Reputation: 1 548

I tried that ( simply using double quotes) and I get a 0 byte result. No error though, so that's progress I guess. – Peter Dixon – 2017-08-15T17:56:31.930

0

I decided to use Windows' FINDSTR command instead. It's more limited but it does work properly on the Windows platform. See https://technet.microsoft.com/en-us/library/bb490907.aspx

Peter Dixon

Posted 2017-08-15T16:50:01.803

Reputation: 11