Hi guys,
i want to validate the no.of colums in a csv file ,but if there is a comma(,) in any of the data values it should skip and count only valid (,) commas.
e.g
1.abc,pqrs,1234,567,hhh
result :4
2.abc,pqrs,1234,567,hhh,"in,valid",end12
result:6
here script should skip the comma inside the{ "in,valid" }.
please advice how to get this count?
This is not the concept of "columns" (as to my understanding). Columns are repeating structures of records (or rows) in a (DB or spread sheet or ...) table or file. E.g. Col1 has "Last Name", Col2 has "First Name", Col3 "CustomerID", etc.
Do you want just the count of data fields/elements in a file? Then try an adaption of Don Cragun's proposal:
First: You can't remove all of the carriage-return characters from an awk script to make a one-liner and get a working awk script.
Second: Please start a new thread for a new problem. You have now changed your requirements three times in four posts.
Third: You can't access awk variables after the awk script exits.
Fourth: What is your script doing? Why not just have the awk script use the variables that are available in the awk script to produce your additional output? For example: