[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Help with wc and subtraction needed



Matthew Benjamin wrote:
> I have a command that I am trying to read a particular amount of
> lines with
>
> wc -l somefile | awk '{print $1}'
>
> when it givs the number of lines, I am trying to find out how to use
> that number in an addition problem. Can someone help me with that?

lines=$(wc -l somefile | awk '{print $1}')
res=$(($lines + 42))

That's bash specific, so depending on how portable you want the script
to be, you'd need to do things slightly differently.  There are a ton
of ways you could do something like this.  Some bash guides might be
helpful:

BASH Programming - Introduction HOW-TO
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

Advanced Bash-Scripting Guide
http://tldp.org/LDP/abs/html/

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I advise you to go on living solely to enrage those who are paying
your annuities. It is the only pleasure I have left.
    -- Voltaire

Attachment: pgpJHv36H5QYm.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]