bash: making a count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash: making a count
# 1  
Old 10-11-2011
bash: making a count

ok basically im trying to count how many people fail a class by comparing there grade by -gt 49

i tried putting a count inside the while loop but i know you cant access a count outside a subshell. is there an easy way to count the number of failures?

Code:
declare -i failcount=0

awk 'match($2,":"){print substr($2,RSTART+1,3)}' class.marks | while read line; do
    if [ $line -gt 49 ] ; then
	(( failcount++ ))
fi
done
echo $failcount

my class.marks file is as follows:

Code:
ID4341:Gwen Camper:72
ID4923:Ron Tomm:100
ID4239111:John Snow:40

# 2  
Old 10-11-2011
Why not use awk to count for you
Code:
failcount=$(awk -F: '$3>49 {F++} END {print F}' class.marks)
echo $failcount

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 10-11-2011
Quote:
Originally Posted by Chubler_XL
Why not use awk to count for you
Code:
failcount=$(awk -F: '$3>49 {F++} END {print F}' class.marks)
echo $failcount

thank you very much

im just learning unix so i still think java when im programming i was unaware you could do this
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making bash script allways executable when transfer ?

Does it possible to make some bash script automatic to be a executable when transfered to another pc...? (5 Replies)
Discussion started by: tomislav91
5 Replies

2. Shell Programming and Scripting

Bash script for making complexes of ligands and receptor

I am working with autodock vina for virtual screening and docking with cygwin. Autodock vina generates conformers for multiple ligands. I want to make the complex of these conformers with receptor. e.g. I have 100 .pdbqt files form vina output and one receptor pdbqt file. By running command- cut... (1 Reply)
Discussion started by: Rajesh Patil
1 Replies

3. Shell Programming and Scripting

Help in making a basic bash script

Hi All, I am trying to monitor CPU load of few processes, with the same name. The output that I get from top is the following 28171 root 20 0 1089m 21m 3608 S 103 0.3 15:16.89 /opt/ppp//h264rtptranscoder.bin --videoPort=14504 --audioPort=14505 27589 root 20 0 1060m 23m... (3 Replies)
Discussion started by: liviusbr
3 Replies

4. Shell Programming and Scripting

Making a bash script and small C program for a homework assignment

Here's the assignment. I'll bold the parts that are rough for me. Unfortunately, that's quite a bit lol. The syntax is, of course, where my issues lie, for the most part. I don't have a lot of programming experience at all :/. I'd post what I've already done, but I'm so lost I really don't know... (1 Reply)
Discussion started by: twk101
1 Replies

5. Shell Programming and Scripting

making code compatible to previous bash versions

First let me explain the scenario I have tywo files as usual file1.txt (it has n rows and 8 columns) $1 $2 $3 $4 $5 $6 $7 $8 Code: 1234567|iufgt|iuoy|iout|white |black |red |90879 1234567|iufgt|iuoy|iout|green |pink |blue |90879... (3 Replies)
Discussion started by: s.deepak
3 Replies

6. Shell Programming and Scripting

Making array of string with bash

in.txt libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good gstreamer-0_10-plugins-base Output should be: libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good gstreamer0_10-plugins-base Then: #!/bin/sh v=(libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good... (5 Replies)
Discussion started by: cola
5 Replies

7. Shell Programming and Scripting

making a list matching certain criteria in bash...

Hello everyone!I am trying to make a mail list(a simple .txt file)in which i put certain records that match specific criteria. Let's say that i have a(sorted by last column file)like this one: 0100567 Bla1 Lala1 100 1234567 Bla2 Lala2 80 8769029 Bla3 Lala3 70 1001007 ... (0 Replies)
Discussion started by: bashuser2
0 Replies

8. Shell Programming and Scripting

Count Directories In bash

Hi ALL I have small script that find 777 dir now i want to count these directories,Keep in mind there are many directories. This IS my code below. #!/bin/bash check=/var/www/html find $check -type d -perm 777 | while read DIR do ... (2 Replies)
Discussion started by: aliahsan81
2 Replies

9. Shell Programming and Scripting

Making a progress gauge in a bash script

Hello once again: One thing that seems to be a nice feature is a progress gauge... so I can see how long an operation will take for a task to complete if it is requiring a lot of processing or the file is enormous. I have seen references to gauge operations, but I don't know anything about it or... (1 Reply)
Discussion started by: ccox85
1 Replies

10. UNIX for Dummies Questions & Answers

Making Application by bash

I'm using Mac OSX. And i want to make an visual application based on bash command. But, apple script doesn't support Terminal command. So please tell me how to turn my dream into a reality. :o I mean purely by bash! (0 Replies)
Discussion started by: Euler04
0 Replies
Login or Register to Ask a Question