In AWK Programming, Write a statement that will print the current PATH to the sc
ID: 3700309 • Letter: I
Question
In AWK Programming, Write a statement that will print the current PATH to the screen. Only write the statement needed. Do not write an entire program.
------------------------------------------------------------------------------------------------------------------------------------------------------
Suppose each line of a file has two names separated by a space. So the file has the format: firstname lastname on each line
Choose the awk statement that will print these names in reverse order with a comma between
them: lastname, firstname. Use only built in field variables. Do not use split.
a. print $lastname, $firstname
b. printf ("%s, %s", lastname, firstname)
c. printf ("%s, %s", $lastname, $firstname)
d. printf("%s, %s", $2, $1);
Explanation / Answer
In AWK Programming, Write a statement that will print the current PATH to the screen. Only write the statement needed. Do not write an entire program.
awk -v P="$(pwd)" 'BEGIN{print P}'
#-v option is used to set the variable P in awk which is pwd i.e. print working directory, then normal BEGIN syntax then print P.
Suppose each line of a file has two names separated by a space. So the file has the format: firstname lastname on each line
Choose the awk statement that will print these names in reverse order with a comma between
d. printf("%s, %s", $2, $1);
#d option is the correct answer, since it is mentioned that we do use only built in field variables, so $2 is 2nd column and $1 is the 1st column