current stuation- I run this line:

Xxxcommand | mail -s 'test on' example@email.com

then I will have the output like below in my email

Name Files(n) Space Calculation
Adam 12345 12345 space/files(n)
Becky 45689 8987
Maryanne 5598 7895

I've got some calculation to make, so a few extra columns are needed.
It's messy. So I want them to aligned according to column from my perl script. Plus addding extra column for calculation based on value from other columns.

My end goal: by running my perl script in linux, which would "take" my output from command, then format it nicely. (the data would be different everytime, so I want to do it for just once, not to edit every time after I get the data output manually like copy and paste data into perl and format it one by one)

if everything works out, when I run my perl script in linux. (that format the output from the command), I will receive an email with the nicely formatted output.
(**Im sorry but idk how to format the styling here to make it aligned with column header)

Name Files(n) Space Calculation
Adam 12345 12345 space/files(n)
Becky 45689 8987
Maryanne 5598 7895

So my main question is : how do I write perl script that can manipulate the output? Should I put the output into a text file in linux first?

Because I just can't see how I can write the perl script that can format or add columns to the output before sending out as mail.

Any advice provided would be appreciated. Thank you.

closed as unclear what you're asking by Wildcard, thrig, Kusalananda, cuonglm, Satō Katsura Mar 22 '17 at 6:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Can you edit your question to include a specific example of what you are trying to achieve? It should be possible to format perl output pretty much any which way you want - see for example Formatted Output with printf – steeldriver Mar 21 '17 at 1:35
  • Hi steeldriver! My main question is that how do I format an output which is generated from a command on linux window. Do I have to put the output into a text file first? Or add a line in perl script to extract the output into my perl? I have added a few lines in my question to let you see my end goal. – Santa Mar 21 '17 at 2:39
  • Pipe data from the command into Perl. Format as you will. This question is too unspecific to answer. Show the input you have and the output you want. – Wildcard Mar 21 '17 at 8:16
  • Hi Wildcard, I've edit my question to show my desire output. My input is some command that generate disc usage information. Output is in email which is unformatted (as shown above under current situation) – Santa Mar 22 '17 at 3:10

can you try this awk command.

$ xxxcommand | awk 'NR==1{printf("%-10s%-10s%-10s%-10s\n",$1,$2,$3,"calculation")}NR>1{printf("%-10s%-10s%-10s%-10s\n",$1,$2,$3,$2/$3)}' | mail_command
Name      Files(n)  Space     calculation
Adam      12345     12345     1
Becky     45689     8987      5.0839
Maryanne  5598      7895      0.709056
  • Hi Kamaraj. I'm sorry but from your line "a.txt", is that mean I have to put the output into text file first? then run this line (with email command) in command window? – Santa Mar 21 '17 at 3:22
  • modified.. please check it – Kamaraj Mar 21 '17 at 8:51
  • in my console window, it showed that "command not found". I did received the email but it's blank.. – Santa Mar 22 '17 at 2:59
  • can you post your command the error message. – Kamaraj Mar 22 '17 at 8:39

Between your Xxxcommand and mail -s... commands do this:

Xxxcommand |
sed -e '
tab( );\
c c c c\
l n n n.
' | tbl - |  nroff -Tascii -ms | grep \. |
mail -s 'test on' example@email.com

N.B.: The c refer to centered columns, l to left-aligned, & n to numerically aligned columns. Modify their numbers to suit your required number of columns.

Not the answer you're looking for? Browse other questions tagged or ask your own question.