13,420
edits
Changes
→INVESTIGATION 2: USING THE AWK UTILITY
# Issue the '''more''' command to quickly view the contents of the '''cars.txt''' file.<br>When finished, exit the more command by pressing the letter <span style="color:blue;font-weight:bold;font-family:courier;">q</span><br><br>The "print" action is the default action of awk to print all selected lines that match a pattern.<br>This action (contained in braces) can provide more options such as printing specific fields of selected lines (or records) from a database.<br><br>
# Issue the following linux command all to display records in the "cars.txt" database that contain the make "ford":<br><span style="color:blue;font-weight:bold;font-family:courier;">wget awk '/ford/ {print}' cars.txt</span><br><br>
# Issue the following linux command all to display records in the "cars.txt" database that contain the make "ford":<br><span style="color:blue;font-weight:bold;font-family:courier;">wget awk '/ford/' cars.txt</span><br><br>What do you notice?<br><br>You can use variables with the "print" action for further processing. We will discuss the following variables in this tutorial:
<pre>
NF - Number of fields in current record
</pre>
For a listing of more variables, please consult your course notes.<br><br>The tilde '''~''' character is used to searchfor a pattern or display standard output for a particular field.# Issue the following linux command to display the model, year, quantity and price in the "cars.txt" database for makes of "chevy":<br><span style="color:blue;font-weight:bold;font-family:courier;">awk '/chevy/ {print $2,$3,$4,$5}' carstxt</span><br><br>
# x