The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Count number of occurences of a word shikhakaul UNIX for Dummies Questions & Answers 8 06-25-2009 11:10 AM
number of occurences of a string siddu_chittari Shell Programming and Scripting 12 12-05-2006 01:09 AM
Counting occurences of different strings in a file Freerider UNIX for Dummies Questions & Answers 4 07-15-2005 10:27 AM
counting the number of lines nayeemmz Linux 6 01-19-2005 12:37 PM
Counting occurences of specific charachter in a file GMMike UNIX for Dummies Questions & Answers 3 10-13-2004 02:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-01-2008
kingofprussia kingofprussia is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
Counting number of occurences

Hi All,

I have to count the number of occurences of the character " ; " in a given line.

I had used the following awk command to achieve the same

echo $KOP.dat|awk '{split($1,my,";"); for(i in my)c++ }END{print c-1}'

My file KOP.dat had the following data

1;"A";"DUN";"405";"022837000";"LOT2";10;10;20;10;39;45;89;87;99;5654654;879878;20080327;"1015";"F1"; " ";"G";"04"

The output given by the above command was 20 but I have 22 semi-colons in the line. The same utility worked good on some ealier occasions can some one please advice.

Thanks
KOP.
  #2 (permalink)  
Old 04-01-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Code:
cat <<EOF | awk -F";" '{semic += (NF-1)} END {print semic}'
1;"A";"DUN";"405";"022837000";"LOT2";10;10;20;10;39;45;89;87;99;5654654;879878;20080327;"1015";"F1"; " ";"G";"04"
EOF
22
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0