3 Replies Latest reply: Oct 15, 2012 12:40 PM by Dude! RSS

    Count columns delimited by pipe, excl those columns contained within quotes

      $  lsb_release -r -i -c -d
      Distributor ID: EnterpriseEnterpriseAS
      Description:    Enterprise Linux Enterprise Linux AS release 4 (October Update 8)
      Release:        4
      Codename:       OctoberUpdate8
      sample text file
      $ cat k1.txt
      hello|"my |name is"|john
      currently use the following code to identify the total number of columns in a flat file delimited by pipe.
      $ cat k1.txt  | awk -F'|' '{ print NF}'
      For line 1, I am expecting 3 however, as the column "my |name is" is enclosed by quotes. Any ideas?
      Note that line2 must remain at 5

      Edited by: user13007502 on 15-Oct-2012 08:10