This discussion is archived
3 Replies Latest reply: Oct 15, 2012 10:40 AM by Dude! RSS

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

kron777 Newbie
Currently Being Moderated
$  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


  • Correct Answers - 10 points
  • Helpful Answers - 5 points