Count number of column in a comma delimited file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count number of column in a comma delimited file
# 8  
Old 01-19-2012
Hi, normally you should start a new thread for that...
Try:
Code:
sed 's/[^,]$/&,/'file

This User Gave Thanks to Scrutinizer For This Post:
# 9  
Old 01-19-2012
echo "10620,"claim processed,paid",reported" | sed 's/$/,/'
# 10  
Old 01-19-2012
oops! Am sorry... Thanks man...

Also, it will be of great help if you give me some threads for dealing with comma delimited files. I can go through them to get a better understanding about comma delimited files. I have been searching over here and in google but couldn't find something solid, it looks like am missing something.

---------- Post updated at 09:34 PM ---------- Previous update was at 09:30 PM ----------

bhargav, your code will append , to the last field even if it is already there.
scrutinizer's code works fine. It appends "," only if it is not there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies

2. Shell Programming and Scripting

Insert a new column with sequence number (Delimiter as comma)

Hi All, I have a file which has data like a,b c,d e,f g,h And I need to insert a new column at the begining with sequence no( 1 to n) 1,a,b 2,c,d 3,e,f 4,g,h Please let me know how to acheive this in unix (3 Replies)
Discussion started by: weknowd
3 Replies

3. Shell Programming and Scripting

Print records which do not have expected number of fields in a comma delimited file

Hi, I have a comma (,) delimited file, in which few fields are enclosed with in double quotes " ". I have to print the records in the file which donot have expected number of field with the line number. File1 ==== name,desgnation,doj,project #header#... (7 Replies)
Discussion started by: machomaddy
7 Replies

4. Shell Programming and Scripting

How to insert a sequence number column inside a pipe delimited csv file using shell scripting?

Hi All, I need a shell script which could insert a sequence number column inside a dat file(pipe delimited). I have the dat file similar to the one as shown below.. |A|B|C||D|E |F|G|H||I|J |K|L|M||N|O |P|Q|R||S|T As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies

5. UNIX for Dummies Questions & Answers

How do you delete cells from a space delimited text file given row and column number?

How do you delete cells from a space delimited text file given row and column number? Letś say the row number is r and the column number is c. Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

6. Shell Programming and Scripting

Find and replace a column that has '' to NULL in a comma delimited using awk or sed

Hi this is my first time posting ever. I'm relatively new in using AWK/SED, I've been trying many a solution. I'm trying to replace the 59th column in a file where if I encounter '' then I would like to replace it with the word NULL. example 0 , '' , '' , 0 , 195.538462 change it to 0... (5 Replies)
Discussion started by: gumal901
5 Replies

7. UNIX for Dummies Questions & Answers

Comma delimited file

Hi All, I have output of sql saved in comma separated file. Now i need to read line by line this file and assign word to a unix variable for further processing Eg: Test file world, 1, 3, 4 earth,2,3,4,5 moon,1,2,3,4 Output should be word1= world word2=1 echo " first word... (7 Replies)
Discussion started by: gwrm
7 Replies

8. Shell Programming and Scripting

Insert comma based on max number of column

Hi, I am new to unix shell shell scripting. I have a specific requirement where I need to append comma's based on the max number of column in the file. Eg: If my source file look something like this, sengwa,china tom,america,northamerica smith,america walter My output file... (8 Replies)
Discussion started by: nicholas_ejn
8 Replies

9. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies

10. Shell Programming and Scripting

Comma Delimited file

I have a comma delimited file that sometimes has addresses details in. The problem is that the address detail can be seen as: "Sample House, Sample Road". When I run a script specifying the file is comma delimited I would like it to ignore comma's that are in between speech marks. Is this... (2 Replies)
Discussion started by: dbrundrett
2 Replies
Login or Register to Ask a Question