On 4/27/06, sandy <[EMAIL PROTECTED]> wrote:
> Hi,
>
>
> The content of file hello.c is as given below.
> I want to count how many + and - are there in this file.
> I had equivalent shel command to count no. of + and -,
>
> grep -e "^+[^+]" diffs.txt | wc -l
> grep -e "^-[^-]" diffs.txt | wc -l
>
You say two different things here. Your email sayas you want to count
the number of '+' and '-', but your grep command count the number lof
lines that start with a single '+' or '-'. Those are two very differnt
things.
> Can anyone help me how to write perl script using regular expression
> which should count no. of + and -.
[snip]
The simplest would probably be something like:
my ($plus, $minus);
while (<>) {
$plus++, next if /^\+[^+]/;
$minus++ if /^-[^-]/;
}
See perlretut for more.
HTH,
--jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential
daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org
values of β will give rise to dom!