Writing Screen output to a file and emailing
Hi,
I have a file with the contents as follows File_Name_Size.txt 1000 FileA 2000 FileB 3000 FileC where the first field is the size of the file in bytes; while the second field is the filename. when I do the following; awk 'BEGIN {printf ("File Totals")} { total = total +1} {printf "%20s,%9d\n", $2, $1 } END {printf "%20s,%9d\n", "Total File size is " $total} File_Name_Size.txt I get the following: File Totals FileA 1000 FileB 2000 FileC 3000 Total File Size is 6000 I want this to be written to a file called File_Name_Size_Total.txt I'm struggling to redirect the printf to this file w/ all syntax error. I'm a newbie and any help would be appreciated on modifying the existing awk statement to write to the file in the format I desire; or any other way to achieve this.. I tried the following: echo `awk 'BEGIN {printf ("File Totals")} { total = total +1} {printf "%20s,%9d\n", $2, $1 } END {printf "%20s,%9d\n", "Total File size is " $total} File_Name_Size.txt` >> File_Name_Size_Total.txt Results are like this File Totals FileA 1000 FileB 2000 FileC 3000 Total File Size is 6000 Thanks a bunch |
Hi,
Welcome to LQ! What about presenting the information or queries too your instructor? |
Hi, welcome to LQ!
Your problem is that you're being too complicated :) Give the echo a miss. Code:
awk 'BEGIN {printf ("File Totals\n")} { total = total +1} {printf "%20s,%9d\n", $2, $1 } END {printf "%20s,%9d\n", "Total File size is " $total}' File_Name_Size.txt >> File_Name_Size_Total.txt Cheers, Tink |
Quote:
The illustration of my example might sound from a Linux class; but this is the scenario i am working at my workplace and needed some guidance. |
Hi,
Sorry! I've seen that example many times. As 'Tink' stated, you do need to simplify. |
Quote:
I'll try this tomorrow..Thanks for your input. So this is what I should try to get the output as I needed ? :) awk 'BEGIN {printf ("File Totals")} { total = total +1} {printf "%20s,%9d\n", $2, $1 } END {printf "%20s,%9d\n", "Total File size is " $total} File_Name_Size.txt >> File_Name_Size_Total.txt File Totals FileA 1000 FileB 2000 FileC 3000 Total File Size is 6000 |
A couple of minor mistkes in there, but yes, basically that's it.
|
Quote:
Code:
awk 'BEGIN {printf ("File Totals")} |
All times are GMT -5. The time now is 06:41 AM. |