The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How count number of fields in a record sureshg_sampat Shell Programming and Scripting 5 01-07-2008 03:30 AM
help me to count no of fields in a file babu@shell Shell Programming and Scripting 7 10-30-2006 10:36 PM
How to count the record count in an EBCDIC file. oracle8 UNIX for Dummies Questions & Answers 1 07-26-2006 04:22 PM
How to add fields in a file bjorb Shell Programming and Scripting 2 10-13-2005 05:11 AM
count fields sskb UNIX for Dummies Questions & Answers 4 12-07-2001 09:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-07-2008
Registered User
 

Join Date: Nov 2005
Posts: 27
Get count on different fields along the raws in a file

Dear All,

Please help me to do this.

I have a file like this.

5|94662240807|94776109911|94776325901|94779007172||||||
5|94112925421|94352240384|94352259199|94672229012||||||
5|94714242745|94722952461|94777660793|94788914465||||||
5|94242224624|94776145420|94776172499|94776531059||||||

so i want to get the count on 9477 number as result from each raw.

result
====

3
0
1
3

Thanks,
Nayanajith.
Reply With Quote
Forum Sponsor
  #2  
Old 02-07-2008
Registered User
 

Join Date: Nov 2007
Location: Belgium & France
Posts: 70
Which language : Shell, Perl, Awk, ... ?
Reply With Quote
  #3  
Old 02-07-2008
Registered User
 

Join Date: Nov 2005
Posts: 27
shell .. (bash)
Reply With Quote
  #4  
Old 02-07-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
nawk '{print gsub("9477", "")}' myFile.txt
Reply With Quote
  #5  
Old 02-08-2008
Registered User
 

Join Date: Jan 2007
Posts: 25
#! /usr/bin/ksh
while read line
do
echo $line |awk -F"9477" '{print NF-1}'
done < file

Last edited by alamitab; 02-08-2008 at 06:38 AM.
Reply With Quote
  #6  
Old 02-08-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
Or:

Code:
awk '{print NF-1}' FS=9477 filename
(use nawk or /usr/xpg4/bin/awk on Solaris)
Reply With Quote
  #7  
Old 02-08-2008
Registered User
 

Join Date: Jan 2007
Posts: 25
the best solution
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0