I am trying to apply two delimiter using awk which are | and @ at the same time using something like this:

awk -F"[@|]"  '{print NF}'

But the output is always taking only one of them as separator but not the other.

O.S: Solaris

  • 1
    Pretty sure the default awk on solaris will not allow a regular expression as the FS. But you should have newer awks installed, perhaps /usr/xpg4/bin/nawk (?? I don't have a solaris box handy) – glenn jackman Mar 1 at 17:48
  • 1
    possibly /usr/xpg4/bin/awk – Jeff Schaller Mar 1 at 18:06
  • bash-3.2$ /usr/xpg4/bin/awk Usage: awk [-F ERE] [-v var=val] 'program' [var=val ...] [file ...] awk [-F ERE] -f progfile ... [-v var=val] [var=val ...] [file ...] – Eng7 Mar 1 at 18:26
  • You may have your syntax wrong? For me using gawk version 4.1.4 the supplied field separators are an array, not a regex, so echo "A|B@B|@@NJK|J|K|@|" | awk -F "[|,@]" '{print NF}' returns 11 (notice the , <comma> separating the array elements). – pbhj Mar 1 at 18:58

The awk provided by Solaris in /usr/bin/awk does not support a regular expression as an argument to -F:

 /usr/bin/awk [-f progfile] [-Fc] [' prog '] [parameters]


 -Fc            Uses the character c as the  field  separator
                (FS)  character.   See  the  discussion of FS

... while the one in /usr/xpg4/bin/awk does:

 /usr/xpg4/bin/awk [-FcERE] [-v assignment]... 'program' -f progfile...
  • 1
    It is misleading that later in the man page the Built-in variable FS is described as input field separator regular expression ... ... until you realize that The /usr/xpg4/bin/awk utility is described on the nawk(1) manual page. – Jeff Schaller Mar 1 at 18:11
  • ack; the words didn't make it from my brain to my fingers -- thanks, Stéphane! – Jeff Schaller Mar 1 at 18:42
  • 1
    Use PATH=$(/usr/xpg4/bin/getconf PATH):$PATH to get the XPG4 tools as the default ones (but you may also have XPG5 and later, see man standards). – Kusalananda Mar 1 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.