In: Computer Science
Email 1
Subject: Awk Utility Assessment 1
File: awk-utility-assessment-1.awk
Create awk commands to remove all occurrences of the word "PCC"
from the input
stream. Your output should be a copy of each input line, with the
word PCC
removed wherever it occurs.
Email 2
Subject: Awk Utility Assessment 2
File: awk-utility-assessment-2.awk
Create awk commands to remove the first and last words from each
line of the
input (assume all lines contain 3 or more words). Your output
should be a
copy of each input line, with the first and last words removed.
Email 3
Subject: Awk Utility Assessment 3
File: awk-utility-assessment-3.awk
Create awk commands to count the number of digits in the
input.
Your output should be a single number.
Email 4
Subject: Awk Utility Assessment 4
File: awk-utility-assessment-4.awk
Create awk commands to calculate the sum of all digits in the
input.
For example, if the input contains the number 123 in the first
line,
and the number 456 in the last line, the output should be 21.
Your output should be a single number.
Answer 1
************
echo "hello PCC PCC" | awk -F" " '{NF=1} 1' OFS="PCC"
Answer 2
************
echo "hello PCC PCC" | awk '{ $1=" "}1 { $3=" "} 3'
Answer 3
************
Answer 4
*************
echo 123 456 | awk -F '' '{ sum = 0; for(i=1; i<=NF; i++) sum += $i; print "sum " sum }'
if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)