Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:58:29+00:00 2026-06-09T11:58:29+00:00

echo Total items: `echo $QUERY1 | awk ‘{print $1}’` echo Total Error: `echo $QUERY1

  • 0
echo "Total items: `echo $QUERY1 | awk '{print $1}'`"
echo "Total Error: `echo $QUERY1 | awk '{print $2}'`"
echo "Percentage: $QUERY2"

How can I send these three things in a single email using mail command. So the mail body should be like this below whenever I get any email, in each line there should be one echo statement-

Total items:-    Some Number
Total Error:-   Some Number
Percentage:-   Some Number

I am running SunOS

bash-3.00$ uname -a 
SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:58:30+00:00Added an answer on June 9, 2026 at 11:58 am

    Your requirement is not completely clear, but try this

    {
        echo "Total items: `echo $QUERY1 | awk '{print $1}'`"
        echo "Total Error: `echo $QUERY1 | awk '{print $2}'`"
        echo "Percentage: $QUERY2"
    } | mail -s "subject" toUser1@xyz.com,toUser2@abc.com
    

    The { .. } pair creates a process group, and all std-output is redirected into the 1 | (pipe), which connects to the std-in of your mail program.

    You may need to use mailx, -s specifies subject, which I see from your other question on this topic that you seem to understand.

    Also sendmail will need to be running and properly configured for any mail to be delivered from the machine that you execute this script.

    IHTH


    Edit: 2015-11-07

    Just got a ‘nice answer’ star for this, and on on review, I’m surprised that I didn’t comment on excessive use of processes. For this case, this can be reduced to one call to awk, i.e.

    awk -v q1="$QUERY1" -v q2="$QUERY2" \
     'END {
        split(q1,q1arr)
        print "Total items: " q1arr[1] \
              "Total Error: " q1arr[2] \
              "Percentage: " q2
    }' /dev/null \
    | mail -s "subject" toUser1@xyz.com,toUser2@abc.com
    

    Or for the one-liner crowd ;-), that is

    awk -v q1="$QUERY1" -v q2="$QUERY2" 'END {split(q1,q1arr);print "Total items: " q1arr[1] "\nTotal Error: " q1arr[2] "\nPercentage: " q2 }' /dev/null | mail -s "subject" toUser1@xyz.com,toUser2@abc.com
    

    The { .. } aren’t needed in this case, as there is only one process connecting to the pipe.

    For a case like a summary report being sent once a day, the original code is completely usable (but non-optimal). However, coding non-optimally leads to bad habits. Calling 5 processes when one will suffice in a loop that runs 1000s of times in a day, will consume compute resources unnecessarily.

    Finally, as the o.p. didn’t include any sample data, the code is only lightly tested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I count the total items in this array below? Array ( [upload]
How can I count the total number items from my twitter feed with DOM?
#!/bin/bash echo 'first line' >foo.xml echo 'second line' >>foo.xml I am a total newbie
echo date(W,strtotime('2010-01-01')); This outputs 53. I would expect it to output 1. Can anyone
PHP Echo or Print functions does not show anything when php is busy with
I want to echo on my homepage the total sales of a product. How
I am getting a NaN error in my ajax callback function and can only
echo date('H:i', time()); // 10:15 echo date('H:i', strtotime($this->deadline)); // 10:05 $delay = time() -
echo timezone_name_from_abbr(, 3600*7, 0); //ok echo timezone_name_from_abbr(, 3600*8, 0); //NOT ok! return nothing! echo
echo date(w,strtotime(date(Y-m-d))); echo date(w,strtotime(date(Y年m月d日))); Save it as utf8.You'll see the second is bigger than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.