help needed with a script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronk
    New Member
    • Mar 2008
    • 2

    help needed with a script

    Hi All.
    I have a simple script that calculates line count in a file and sends an email with the file as an attachment.
    The issue I have is ,I want to subtract 1 from the line count .

    Noflines=`wc -l $1 |cut -c1-8`
    ans=(($Noflines-1)
    echo $ans

    the script is not executing at line 2..ans=
    I think this is because iam subtracting integer from a string.is that true.what can i change here to make this work.
    can someone please help me out.
    Thanks ,Ron
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by ronk
    Hi All.
    I have a simple script that calculates line count in a file and sends an email with the file as an attachment.
    The issue I have is ,I want to subtract 1 from the line count .

    Noflines=`wc -l $1 |cut -c1-8`
    ans=(($Noflines-1)
    echo $ans

    the script is not executing at line 2..ans=
    I think this is because iam subtracting integer from a string.is that true.what can i change here to make this work.
    can someone please help me out.
    Thanks ,Ron
    use 'expr' command to achieve this:

    ans=`expr $Noflines - 1`

    NOTE:expression surrounded character is not single quote.

    Comment

    • ronk
      New Member
      • Mar 2008
      • 2

      #3
      Thanks ashitpro .
      It solved my problem.thanks again.

      Comment

      Working...