-1

I need to parse some CSV and there is a limitation that it has to be awk/bash. The below is the best I got, but it returns

Ecology",Biology

but I would need "PhD, Ecology". Any help would be very much appreciated!

echo '6,John Smith,"PhD, Ecology",Biology Department' |
    awk 'BEGIN{FPAT = "\"[^\"]*\"|[^,]*"} {print $3}'

The similar question here did not help me: Parse a csv using awk and ignoring commas inside a field

awk version 20200816

MacOS.

6
  • 1
    I get proper output with GNU Awk 5.1.0 Commented Mar 6, 2024 at 12:27
  • 1
    What is your version of awk? awk --version Commented Mar 6, 2024 at 12:28
  • Hm.. I'm on Mac, awk version 20200816. Will check if I can get a different version. Commented Mar 6, 2024 at 12:36
  • same command with gawk instead works fine, thanks a lot for the comment!!! Commented Mar 6, 2024 at 12:37
  • 1
    Looks you don't have GNU awk, that's the reason. Try to install GNU version with homebrew: brew install gawk Commented Mar 6, 2024 at 12:37

1 Answer 1

0

It looks like you don't use GNU awk.

You need to install GNU version with homebrew:

brew install gawk
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.