Question
I cant get this to output anything on my MAC using TextEdit. Project 3-17 To refine and automate the vendor report, you can create a
I cant get this to output anything on my MAC using TextEdit.
Project 3-17
To refine and automate the vendor report, you can create a shell script that uses the awk command. This new script, however, includes only the awk command, not a series of separate commands. You will then call the Awk program using awk with the f option. This option tells Awk that the code is coming from a disk file, not from the keyboard. You will present the action statements inside the Awk program file in a different way, which resembles programming code. The program file includes additional lines needed to print a heading and the current date for the report.
The next steps show what happens when you enter the Awk program using a file like this. You use the FS variable to tell the program what the field separator is in this example, a colon. FS is one of many variables that awk uses to advise the program about the file being processed. Other codes you see here set up an initial activity that executes once when the program loads. BEGIN followed by the opening curly brace({) indicates this opening activity. The closing curly brace (}) marks the end of actions performed when the program first loads. These actions print the headings, date, and dashed lines that separate the heading from the body of the report.
To create the awk script:
- Type the following in gedit (or other text editor) and save the file as awrp.
BEGIN {
{ FS = ":" }
{ print "\t\tVendors and Products " }
{ "date" | getline d }
{ printf "\t %s ",d }
{ print "Vendor Name \t\t\t Product Names " }
{ print "=============================== " }
}
{printf "%-28s\t %s ",$1,$2}
In the code you typed, the getline option is designed to read input. In this case, it reads the date and places it into the d variable, which then is printed via the printf command.
- Type awk f awrp vreport > v_report and press Enter.
This means using the Awk program, combine the fields from the awrp file with the fields from the vreport file, and send them to a new file called v_report. Type cat v_report and press Enter. What is your output?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started