Question

(UNIX/LInux) Please download the file from course documents to do the following exercises after going through...

(UNIX/LInux) Please download the file from course documents to do the following exercises after going through the awk handout:

1. Print all the phone numbers.

2. Print Dan's phone number.

3. Print Susan's name and phone number.

4. Print all last names beginning with D.

5. Print all first names beginning with either a C or E.

6. Print all first names containing only four characters.

7. Print all first names of all those in the 916 area code.

8. Print Mike's campaign contribution. Each value should be printed with a leading dollar sign; e.g. $250 $100 $175

9. Print all last names followed by a comma and the first name.

10. Write an awk script called facts that:

a. Prints full names and phone numbers for the savages.

b. Prints Chef's contributions.

c. Prints all those who contributed $250 the first month.

I can't add the handout but I just want to know what commands I would have to type since I am a bit confused

Homework Answers

Answer #1
Q1: Print all the phone numbers.
A: awk -F: '{print $2}' awkdata
Q2: Print Dan's phone number.
A:  awk -F: '/Dan/{print $2}' awkdata 
Q3: Print Susan's name and phone number.
A:  awk -F: '/Susan/{print $1,$2}' awkdata 
Q4: Print all last names beginning with D.
A: awk -F"[ :]" '$2~/^D/{print $2}' awkdata
Q5: Print all first names beginning with either a C or E.
A: awk  '$1~/^(C|E)/{print $1}' awkdata
Q6: Print all first names containing only four characters.
A: awk  '$1~/^[A-Za-z][A-Za-z][A-Za-z][A-Za-z]$/{print $1}' awkdata
Q7: Print the first names of all those in the 916 area code.
A: awk '/(916)/{print $1}' awkdata
Q8: Print Mike's campaign contributions. Each value should be printed with a leading dollar sign; e.g., $250 $100 $175.
A: awk -F: '/Mike/{print "$"$3,"$"$4,"$"$5}' awkdata
Q9: Print last names followed by a comma and the first name.
A: awk -F"[ :]" '{print $2 ", " $1}' awkdata
Q10: Write an awk script called facts that
A:           
         1.
           Prints full names and phone numbers for the Savages.
            BEGEN{
                FS=":"
            }
            {
                /Savage/{print $1,$2}
            }
        2.
          Prints Chet's contributions.
            BEGIN{
                FS=":"
            }
            {
                /Chet/{print $3,$4,$5}
            }
          3.
           Prints all those who contributed $250 the first month.
            BEGIN{
                   FS=":"
            }
            {
                if( $3>250 )
                    print $0
            }
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions