problem with count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with count
# 1  
Old 11-06-2006
problem with count

Hi,
consider this file "master" which contains data as
11:skjs:24:asd2
1:skdfjk:23:sfdf
12:su:25:jkh5
13:gre:22:kljl7
14:sai:34:kjg7

I am trying to enter data into the file "master"

i want to count the number of times 11 is present in the file "master" that to in the first filed itself.
the delimetter is ":"

i am using the command:

grep -c 11 master
answer) 1

grep -c 1 master
answer) 5.
but 5 is not the answer as 1 occurs only once in the 2nd row.
# 2  
Old 11-06-2006
try this:

Code:
grep -c "^11:"

if you can't recognise that "11" does contain "1", then maybe you need to do a bit of maths
# 3  
Old 11-06-2006
u r not understanding what i am saying.

if i want to count the number of 1's in the 1st field of the file
i need to get the count as only 1 not 5.
i am considering the fields as id:name:age:address
i want to get the count of id=1
# 4  
Old 11-06-2006
then what you want is:

Code:
grep -c "^1:" master

# 5  
Old 11-06-2006
Try
Code:
grep -c "\<1\>" in.txt

or
Code:
grep -wc "1" in.txt

if your grep supports w and c flags.
# 6  
Old 11-06-2006
thanks a lot buddies
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 find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies

2. Shell Programming and Scripting

problem to count number of words from file

hi every one i have written this simple shell for counting number of word that user need to find from file but i have get several error when run it. can someone tell me the problem ? echo "Enter the file name" read file echo "enter word" read word for i in \`cat $file` do if then... (1 Reply)
Discussion started by: nimafire
1 Replies

3. Shell Programming and Scripting

Process count problem in script

Hi, I am trying to make a script which should execute if the same is not getting executed already. To implement this check, I wrote a fragment of code as below $ cat abc.sh #!/bin/bash check=0 #grepping "sh -x abc.sh" because if i check only for "abc.sh" and the file is open in say... (12 Replies)
Discussion started by: sam05121988
12 Replies

4. Shell Programming and Scripting

Loop renaming files w/ a count problem

:wall: Hello there, basically in my program where im stuck at is when it comes to rename the files in a loop. - the program counts the number of files w a given name (works!) - and then if the number of files is greater or equal to the MAX_VERSIONS (numbers of files allowed w the... (1 Reply)
Discussion started by: thurft
1 Replies

5. Shell Programming and Scripting

Perl code- word count problem

Hi, I am having .csv files contains some row - Info: Value of field name 'SecurityExchange' is not supported ","Original Order Tuple Please see the below perl code carefully- /Info: (+),Original (\w+) Tuple/ and do { ($category, $type) = ($1, $2); if($type eq 'Execution')... (1 Reply)
Discussion started by: pspriyanka
1 Replies

6. Shell Programming and Scripting

Awk Count Pattern problem.

I want to keep a count of a all the records processed in a input file. The input file would have a lot of data containing various information. Lets say I make a pattern that only prints out data with the amount $37.57. How would I go about keeping track of how many $37.57 appears? I have... (2 Replies)
Discussion started by: Boltftw
2 Replies

7. UNIX for Dummies Questions & Answers

Record count problem using sed command

Hi, I have a script which removes 2 header records and 1 trailer record in a list of files. The commands doing the actions are sed '1,2d' $file > tempfile1.dat sed '$d' < tempfile1.dat > $output.txt Its working fine for all records except a file having size=1445509814 and number of... (2 Replies)
Discussion started by: ayanbiswas
2 Replies

8. UNIX for Dummies Questions & Answers

Problem count with wc-l command

Hi All, I'm trying to count how many line in my *.txt file. My *.txt file has 1937 lines. The problem is : when I use wc -l command the result is 1936. Again, I did some test. I create a new file with 100 lines with text editor (Notepad ++, Ultra edit). And when I count it again with wc... (2 Replies)
Discussion started by: kunimi
2 Replies

9. Shell Programming and Scripting

Complex file count problem

Hi all! I have a question regarding possibilities to do line counts. SEARCH_VAR=TEX rsh $REM_HOST -l $REM_USER "cd $REM_DIR; ls *$SEARCH_VAR* 2> /dev/null" | sort -n | awk 'BEGIN { FS = "-" } ; { print $1"\t"$0 }' Will produce an output on the screen like this: 483 483-SOME-TEXT-1... (1 Reply)
Discussion started by: bbergstrom74
1 Replies

10. UNIX for Dummies Questions & Answers

Word count problem

I have a text file that has 5719 rows when I open it up in a text editor. When I do a wc -l in Unix however, it says that I have 5718 rows. What could be causing this difference? (1 Reply)
Discussion started by: ssmith001
1 Replies
Login or Register to Ask a Question