Hello, I am new to awk and I am having a hard time figuring out how do get this to work:
I want to process a csv file and write each column value out to a file, so i wrote this script:
awk'{
for(i=1;i<NF;i++){
ct[$1]+=1
}
for(val in ct){
print val
}
}' FS="," < mydata.csv
Now that runs and prints out to the screen, but the order it prints things out is not the order they are read in the columns....so how do i print out in the sam order they are read in?
I tried for the second loop(instead of w in ct):
for(j=0;j<NF;j++){
print ct[$j]
}
but that just prints 1 repeadetly on each line.
I feel it is somethign simple I am missing but have not been able to solve it.
What should I be doing?
Thanks,
CR
I want to process a csv file and write each column value out to a file, so i wrote this script:
awk'{
for(i=1;i<NF;i++){
ct[$1]+=1
}
for(val in ct){
print val
}
}' FS="," < mydata.csv
Now that runs and prints out to the screen, but the order it prints things out is not the order they are read in the columns....so how do i print out in the sam order they are read in?
I tried for the second loop(instead of w in ct):
for(j=0;j<NF;j++){
print ct[$j]
}
but that just prints 1 repeadetly on each line.
I feel it is somethign simple I am missing but have not been able to solve it.
What should I be doing?
Thanks,
CR