Create an .csv/excel file using shellscript

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create an .csv/excel file using shellscript
# 8  
Old 07-06-2011
awk 'BEGIN{OFS=";"}{++A[$0]}END{for(i in A) {f=i".csv";print "Product_name"  OFS "count" >f ; print i OFS A[i] >>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[i] >>f}}' input_Products.txt

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

Last edited by ctsgnb; 07-06-2011 at 07:22 AM..
# 9  
Old 07-06-2011
Java To create a .csv/excel file using shellscript

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
# 10  
Old 07-06-2011
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[i]}' tst
.Net ;8
IBM Websphere;8
MicroSoft excel;8
# awk 'BEGIN{OFS=";";print "Product_name" OFS "count"}{++A[$0]}END{for(i in A) print i OFS A[i]}' tst
.Net ;8
MicroSoft excel;8
IBM Websphere;8

On which plateform are you ?
# 11  
Old 07-13-2011
To create a .csv/excel file using shellscript

Attachment 2194Platform 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..
# 12  
Old 07-15-2011
Try this,
 awk '{a[$0]++} END {for (i in a) { print "Product Name,Count\n"i","a[i] > i".csv"}}' inputfile

# 13  
Old 07-15-2011
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 this..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to sort a column in excel/csv file?

I have to sort the 4th column of an excel/csv file. I tried the following command sort -u --field-separator=, --numeric-sort -k 2 -n dinesh.csv > test.csv But, it's not working. Moreover, I have to do the same for more than 30 excel/csv file. So please help me to do the same. (6 Replies)
Discussion started by: dineshkumarsrk
6 Replies

2. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

3. Shell Programming and Scripting

Data formatting in CSV file to EXCEL

Hello friends I want to convert an csv file on unix (which is generated by a ETL application) to a formatted excel sheet like .I have roughly like 28 columns 1)All numbers need to be stored as numbers with leading zeros-like format as text for this column to preserve leading zeroes e.g... (6 Replies)
Discussion started by: etldev
6 Replies

4. UNIX for Dummies Questions & Answers

How to Create excel file(.csv) using shell script?

Hi, i have shell script which compiles n number of test cases and execute them one by one. i want to create report in excel through script in which two columns namely "test id" and "release".second column have two subcolumns namely compiles and excutes. so i want first column should display test... (15 Replies)
Discussion started by: RamMore123
15 Replies

5. Shell Programming and Scripting

mail a csv file as an excel sheet!

Hi, The result of a script is a csv file in the following format: cat $file_name DATA_USAGE_FACT,YES_NO_FLG,TARGET_TABLE,YES_NO_FLG,1,0,15,0 DATA_USAGE_FACT,DATE_OF_CREATION,TARGET_TABLE,DATE_OF_CREATION,29,9,19,0 DATA_USAGE_FACT,UPDATION_DATE,TARGET_TABLE,UPDATION_DATE,29,9,19,0... (3 Replies)
Discussion started by: dips_ag
3 Replies

6. Shell Programming and Scripting

csv file to excel issue

Hi, I am trying to attach and email a csv file in the form of an excel sheet. And I have been successful in doing this. But after some days I realised that some fields in the csv file are also having commas because of which this field is getting splitted in columns in the excel sheet. ... (5 Replies)
Discussion started by: girish1428
5 Replies

7. UNIX for Dummies Questions & Answers

Excel File to CSV

Hi All, I have to convert the excel file which will be placed in the Unix box to a CSV file using a shell script. Please Advise. Thanks & Regards, Kumar66 (1 Reply)
Discussion started by: kumar66
1 Replies

8. Shell Programming and Scripting

How to sort columns in excel(csv) file

i want sort columns with headers based on another file headers file1 eg: i'm having an empty file with only coumn names like lastname firstname title expirydate stlcno status etc... another file with same column names and some other as well but in different order... file2 eg:firstname... (2 Replies)
Discussion started by: Man83Nagesh
2 Replies

9. UNIX for Dummies Questions & Answers

create excel file

Hi, How can I create an excel file from a txt file using shell script. Please do a help for me. Thanks, Regards, Milton (6 Replies)
Discussion started by: miltony
6 Replies

10. Shell Programming and Scripting

text file to excel or csv

Hi, I have a text file like ---------------------- aaa|bbb|ccc|ddd|eee fff|gggg|hhhhhh|kkkk -------------------- I have a script which will transfer(thourgh FTP) this text file to windows system. But I want to covert it into excel or CSF then upload into windows system.. thanks (9 Replies)
Discussion started by: srikanthus2002
9 Replies
Login or Register to Ask a Question