Unix Programming - Calculate percentages

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2005 > Calculate percentages





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Calculate percentages
Dion

2005-10-24, 3:48 pm

I am a beginner in UNIX and I want to write a shell script calculating
the proportion of one-line comments in any C++ program. Could anyone
help me please? Thanks!

Bit Twister

2005-10-24, 3:48 pm

On 23 Oct 2005 13:32:20 -0700, Dion wrote:
> I am a beginner in UNIX and I want to write a shell script calculating
> the proportion of one-line comments in any C++ program. Could anyone
> help me please? Thanks!


You could use grep to find the comment line and wc to count lines.

man grep
man wc

There there is
! bash script introduction documentation
http://www.tldp.org/LDP/intro-linux/html/index.html
! bash script advanced documentation
http://www.tldp.org/LDP/abs/html/index.html
Dion

2005-10-24, 3:48 pm

I already did that and i counted the commented lines. However, when I
tried to set variables and assigned these numbers (from the grep and
wc), I couldn't execute my percentage calculation (I tried something
like: set x="grep.....",
set y="grep...." and set proportion= ( $x / $y ) * 100. It didn't
work!)

Bit Twister

2005-10-24, 3:48 pm

On 23 Oct 2005 13:51:29 -0700, Dion wrote:
> I already did that and i counted the commented lines. However, when I
> tried to set variables and assigned these numbers (from the grep and
> wc), I couldn't execute my percentage calculation (I tried something
> like: set x="grep.....",


hmm, cut/paste these next two lines in a terminal and see what happens.

x=$(wc -l < /etc/profile)
echo $x

> set y="grep...." and set proportion= ( $x / $y ) * 100. It didn't
> work!)




Well, you must have missed something when you speed read the provided
urls.

http://www.tldp.org/LDP/abs/html/arithexp.html

Chris F.A. Johnson

2005-10-24, 3:48 pm

On 2005-10-23, Dion wrote:
> I am a beginner in UNIX and


...a beginner on Usenet. Unfortunately, using google to post to
newsgroups is not going to give you a good experience for learning.

One of the first principles of Usenet is that you do not post the
same message to multiple groups unless you cross-post, that is, one
message is sent to more than one group. Newsreader software (unlike
the broken Google Groups interface) knows when you have already
read an article, and doesn't display it again when it appears in
another newsgroup.

If you post the same message separately to more than one group,
newsreaders cannot tell that it has already been seen, and you have
to check in more than one place for answers.

> I want to write a shell script calculating
> the proportion of one-line comments in any C++ program. Could anyone
> help me please? Thanks!
>



--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========================================
==========================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com