Counting occurence of a coma


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting occurence of a coma
# 1  
Old 01-22-2004
Counting occurence of a coma

I have a .csv file that I would like to count on each line the occurences of the coma. Each line should have the same amount, but as an integrity check I would like to include in my script this count.

What is the best way of doing this?
# 2  
Old 01-22-2004
You could use awk to reject records that do not have the required number of fields, e.g. assuming records should have 5 fields...
Code:
awk -F, NF!=5 datafile > rejectfile
if [ -s rejectfile ]
then
    echo abort
fi

# 3  
Old 01-22-2004
Thanks very much
# 4  
Old 01-22-2004
Awk is a great language.

The best book imho is "The Awk Programming Language" by Aho/Weinberger/Kernigan... the creators btw...

It is a little grey book about half an inch thick...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print in next line after coma

Hi, I have a file like seen below. apple, orange, grapes pineapple tomato, potato egg I need a output like apple orange grapes pineapple tomato potato (8 Replies)
Discussion started by: jayadanabalan
8 Replies

2. Shell Programming and Scripting

Print between patterns - first occurence, second occurence etc

I have a file # cat asasas AAAAAA 11 22 33 44 BBBBB NILNILNIL AAAAAA 22 33 44 55 66 77 88 BBBBB NILNILNIL (2 Replies)
Discussion started by: anil510
2 Replies

3. Shell Programming and Scripting

Percentage of occurence

Dear all, I have data like below and i need to add coloumn before the COUNT field to see the Percentage out of all COUNT field value for respective raw. ============================================= COUNT CODE sConnType tConnType... (6 Replies)
Discussion started by: Iroshan
6 Replies

4. Shell Programming and Scripting

Change first occurence

I'm not getting the syntax correct to change a line only on the first occurrence: I've tried to change only the first match and I've tried to change the from the second match forward sed 's/<B>PT#/<tr><td class=\"pt1\" width=\"40%\"><B>pt#/1' $file > tmpfile.html sed ... (0 Replies)
Discussion started by: dba_frog
0 Replies

5. UNIX for Dummies Questions & Answers

counting the occurence of a word

In a file I have to count a particular word. like i need apache how many times. I tried this $ tr "\011" "\012\012"<foo1 | tr -cd "" |sort\uniq -c but I got result like this 32 apache 18 dns 12 doctor Please sugest me (4 Replies)
Discussion started by: pranabrana
4 Replies

6. UNIX for Dummies Questions & Answers

Counting occurence of a particular character on each line

Hi, I have the following data in a flat file: abcd_efgh_ijkl_20080522.dat|20080602222508|1357 abcd_efgh_ijkl_20080522.dat|20080602222508|1357 abcd_efgh_ijkl_20080522.dat|20080602222508|1357 I need to check the no. of occurence of "|" (pipe) on each line and the output should look like below:... (4 Replies)
Discussion started by: hey_mak
4 Replies

7. UNIX for Dummies Questions & Answers

counting the occurence of particular characters

I want to list the occurence of particular characters in a line. my file looks like this a,b,c,d e,f,g h,y:e,g,y s f;g,s,w and I want to count how many commas are in each line so the file in the end looks like this: a,b,c,d 3 e,f,g 2 h,y:e,g,y s 3 f;g,s,w ... (2 Replies)
Discussion started by: Audra
2 Replies

8. Shell Programming and Scripting

Extracting the last occurence

Hi All, Is there any awk or unix command that i can make use such that the output will be as desired ? The code will extract the latest pattern starting from the term above the asterix till the end of the input Input: ******** aaa bbb 2007 ******** 123 234 134 ******** xxx yyy 2007... (9 Replies)
Discussion started by: Raynon
9 Replies

9. Shell Programming and Scripting

difference between double inverted coma and single inverted comma

Whats the basic difference between double inverted comma and single inverted comma and no comma applied at all? Eg1 if Eg2 if iEg3 f (1 Reply)
Discussion started by: abhisekh_ban
1 Replies

10. UNIX for Advanced & Expert Users

First Occurence

Hi, This is the format of the file that i have StartDate:10/01/06 EndDate :10/02/06 Cno Ccode 1 10 2 11 StartDate:10/03/06 EndDate :10/04/06 Cno Ccode 2 13 4 12 StartDate:10/01/06 EndDate :10/02/06 (5 Replies)
Discussion started by: kkm_job
5 Replies
Login or Register to Ask a Question