Question

unix script

Consider the file cars provided. The columns in the file contain from left to right: the car’s make, model, year of manufacture, mileage, and price

Write an awk script that displays the year of manufacture, price, mileage, and model of all the cars priced at or less than $3,000. Below is a report format example:

Cars costing at most $3,000

Year                 Price                Mileage            Model

------                 -------               ----------            ---------

1970                $2500              73                    fury

END OF THE LISTING


blym fury 1970 73 2500 chevy malibu 1999 60 3000 ford mustang 1965 45 10000 volvo s80 1998 102 9850 ford thundbd 2003 15 10500 chevy malibu 2000 50 3500 bmw 325i 1985 115 450 honda accord 2001 30 6000 ford taurus 2004 10 17000 toyota rav4 2002 180 750 chevy impala 1985 85 1550 ford explor 2003 25 9500

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Syntax for awk

awk -v OFS='delimter' 'BEGIN{print "header"; condition {print "row"}; END{print "footer"}}' file

Command to print all cars priced at or less tha $3000

awk -v OFS='\t' 'BEGIN{print "Year\tPrice\tMileage\tModel\n------\t------\t------\t-----"}; $5 <= 3000 {print $3"\t""$"$5"\t"$4"\t"$2}; END{print "END OF THE LISTING"}' file

Note: \t(space) used as delimiter for each line and each column is held under index starting from1 and can be referenced as $<column_number> eg: $5 for fifth column

Sample Input

$ cat > input.dat plym fury 1970 73 2500 chevy malibu 1999 60 3000 Ford mustang 1965 45 10000 volvo s80 1998 102 9850 ford thundbd 2003 15 10500 chevy malibu 2000 50 3500 bmw 325i 1985 115 450 honda accord 2001 30 6000 ford taurus 2004 10 17000 toyota rav4 2002 180 750 chevy impala 1985 85 1550 ford explor 2003 25 9500

Sample Output

Add a comment
Know the answer?
Add Answer to:
unix script Consider the file cars provided. The columns in the file contain from left to...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use the testfile1.txt to carry out the following tasks and write the results in a single...

    Use the testfile1.txt to carry out the following tasks and write the results in a single file named as your .txt and upload: Q) Using a sed command, delete all ford cars. textfile 1.txt contains: plym fury 1970 73 2500 chevy malibu 1999 60 3000 ford mustang 1965 45 10000 volvo s80 1998 102 9850 ford thundbd 2003 15 10500 chevy malibu 2000 50 3500 bmw 325i 1985 115 450 honda accord 2001 30 6000 ford taurus 2004 10 17000...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT