0

when I cat the csv file for head | wc -l it gives me answer as 1 since there are comma in between , I wanted it to eliminate the comma and give me the count as 7

Eg :

cat file1.csv 
row1,row2,row3,row4,row5,row6,row7

cat file1.csv | head -1 | wc -l
1 

But I wanted the answer to be 7 as it should give me counts of the rows

janos
  • 120,954
  • 29
  • 226
  • 236
John Joel
  • 15
  • 1
  • 4

1 Answers1

3

You could replace the , with newline using tr:

tr , '\n' < file1.csv | wc -l

Or you could count the fields with awk:

awk -F, '{ print NF }' < file1.csv

Or you could delete everything but the commas with sed and then count the characters:

sed -e 's/[^,]//g' file1.csv | wc -c
janos
  • 120,954
  • 29
  • 226
  • 236