1

I'm trying to extract some data from a CSV file, and the command line that works under linux is not working with mawk for windows.

Using WSL, the following command works as expected:

    mawk -F, '$16 == "Good" {print $4}' < *GOL*_approval.txt

However, in powershell, the following command gives completely different results:

    mawk -F',' '$16 == "Good" {print $4}' *GOL*_approval.txt

I think it might be a quoting option, but I've tried everything I can think of.

Sam Alleman
  • 141
  • 7
  • Please, post some sample data with the related expected output and _completely different results_ you got with that data. Don't post them as comments, images, tables or links to off-site services but use text and include them to your original question. Thanks. – James Brown Aug 27 '21 at 17:26

2 Answers2

2
  • PowerShell on Windows doesn't support what is called native globbing in PowerShell (Core) on Unix-like platforms, so you must resolve your globbing (wildcard) pattern explicitly.

  • Up to at least PowerShell 7.1, a long-standing bug when passing arguments to external programs that have embedded " characters requires them to be manually escaped as \"

    • This may finally get fixed in the upcoming v7.2 - see this answer.
# Manual escaping of " as \" is required up to v7.1
# This may change in v7.2
mawk -F',' '$16 == \"Good\" {print $4}' (Get-Item *GOL*_approval.txt).FullName
mklement0
  • 382,024
  • 64
  • 607
  • 775
0

What is your version of mawk? http://gnuwin32.sourceforge.net/packages/mawk.htm ?

Also you are missing a < on the second item before the < *GOL*_approval.txt and putting extra ' in -F','

Rui Claro
  • 53
  • 5
  • 2
    Powershell won't let me use the "<" redirector, but it works fine without it. I have to quote the field separator in powershell also, for some reason. I'm not really sure what version I'm using, is there an easy way to tell? I've been playing around with a reduced dataset and I am just not getting the results that I expect. – Sam Alleman Aug 27 '21 at 17:36
  • @SamAlleman, use `mawk -W version` to print the version number. – mklement0 Aug 27 '21 at 17:44
  • This should be a comment, not an answer. – Ed Morton Aug 27 '21 at 19:31