Csv file separate using awk

Hi,

I have file like below

apple,orange,pineapple,pappya,guva,avocado

want to store as

apple
orange
pineapple
pappya

I tried below command to seprate first field

command1:
 
/usr/xpg4/bin/awk -F',' 'print {$1}' filename
 
command2:
 
/usr/xpg4/bin/awk 'BEGIN {FS=',';} print{$1}' filename

but I am getting error, both are not working

awk '{n=split ($0,tab,",")}END{for(i=0;i<=n;i++)print tab}' filename
awk '1' RS=',' file

Hi stew,
Do you really just want to print the 1st four fields?

What error messages are you getting?

Hi protocomm,
Assuming that stew isn't using a Solaris system and wants to print all fields (instead of just the first four shown as the desired output), the following would be simpler:

awk -F, '{for(i = 1; i <= NF; i++) print $i}' filename
1 Like