Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    Maybe edit your answer to use singles quotes instead for escaping. It will work with any character (except '). Also, it has a strange behavior with empty lines. Commented Aug 15, 2011 at 16:08
  • The question specifically uses " so I feel obliged to make the code work with it. It depends what shell you are using weather the character needs to be escaped but bash/tcsh will both need to escape " Commented Aug 15, 2011 at 16:10
  • 1
    Of course, but there is no problem with -F'"'. Commented Aug 15, 2011 at 16:12
  • 1
    +1 What a good idea to use FS.... This will resolve the blank-line showing -1, and, for example, the "$1" from the bash commandline. ... awk -F"$1" '{print NF==0?NF:NF-1}' filename Commented Aug 15, 2011 at 22:19
  • 1
    Also work with multiple chars as separator... useful ! Commented Sep 30, 2016 at 15:35