Create an .csv/excel file using shellscript

In my file, i have 4 Product names(For ex:Microsoft excel, Oracle,.Net,IBM websphere,..etc.,) I want this 4 Products in 4 individual .csv/excel file after running the script with those products related information.

In my file, i have 4 Product names -- where is your file ? how it looks like ?

Please post sample input file and desire output.

The data in notepad file and i want the products count in excel/.csv file

is it assingment ?

read about the sort and uniq command. you will get the answer

awk 'BEGIN{OFS=";";print "Product_name" OFS "count"}{++A[$0]}END{for(i in A) print i OFS A}' input_Products.txt >output_Products.csv

The output_Products.csv can then be open in an excel sheet

Or something like

sort input_Products.txt | uniq -c | awk 'BEGIN{print "Product_name;count"}{x=$1;sub(".*"$2,$2);print $0";"x}'

Thank u.
do we have a chance to create a excel sheet for each and every Product like,

Product_Name Count
Microsoft excel 8 ---> In one file saved as microsoftexcel.csv

Product_Name Count
.Net 8 ----> In another file called as .Net.csv

awk 'BEGIN{OFS=";"}{++A[$0]}END{for(i in A) {f=i".csv";print "Product_name"  OFS "count" >f ; print i OFS A >>f}}' input_Products.txt

If willing to remove space in filename:

awk 'BEGIN{OFS=";"}{++A[$0]}END{for(i in A){f=i".csv";gsub("  *",z,f);print "Product_name" OFS "count" >f;print i OFS A >>f}}' input_Products.txt

If running on SunOS or Solaris plateform, use "nawk" or "/usr/xpg4/bin/awk" instead of "awk"

awk 'BEGIN{OFS=";";print "Product_name" OFS "count"}{++A[$0]}END{for(i in A) print i OFS A[i]}' input_Products.txt >output_Products.csv

I executed it, it is fine but, it is giving extra number ;2 as shown below

Product_name;count;2.Net ;8IBM Websphere;8MicroSoft excel;8Oracle;8
why ? I do not want it in output

I have no idea, for me it works fine :

# nawk 'BEGIN{OFS=";";print "Product_name" OFS "count"}{++A[$0]}END{for(i in A) print i OFS A}' tst
Product_name;count
.Net ;8
IBM Websphere;8
MicroSoft excel;8
Oracle;8
# awk 'BEGIN{OFS=";";print "Product_name" OFS "count"}{++A[$0]}END{for(i in A) print i OFS A}' tst
Product_name;count
.Net ;8
MicroSoft excel;8
IBM Websphere;8
Oracle;8

On which plateform are you ?

Platform is windows and it is working fine.

I need one more help that conside that the notepad has Product names and to create excel/.csv file for individuall product from notepad

The input and expected output files were attached. please find..

Try this,

 awk '{a[$0]++} END {for (i in a) { print "Product Name,Count\n"i","a > i".csv"}}' inputfile

Thanks alot.

It is working fine, now we are getting output with awk command.

Do we have an chance to write it in code by using array to call data from file and to count the occurences.....like this..