Changes

Jump to: navigation, search

Tutorial11: Sed & Awk Utilities

646 bytes added, 10:07, 25 July 2020
INVESTIGATION 2: USING THE AWK UTILITY
# 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}' cars.txt</span><br><br>Notice that a space " " is the delimiter for the fields that appear as standard output.<br><br>
# Issue the following linux command to display all plymouths (plyms) by model name, price and quantity:<br><span style="color:blue;font-weight:bold;font-family:courier;">awk '/chevy/ {print $2,$3,$4,$5}' cars.txt</span><br><br>You can also use comparison operators to specify conditions for processing with matched patterns when using the awk command. Since they are used WITHIN the awk expression, they are not confused with redirection symbols<br><br> Comparison Operators:<br><br>'''<''' &nbsp;&nbsp;&nbsp;&nbsp;Less than<br>'''<=''' &nbsp;&nbsp;Less than or equal<br>'''>''' &nbsp;&nbsp;&nbsp;&nbsp;Greater than<br>'''>=''' &nbsp;&nbsp;Greater than or equal<br>'''==''' &nbsp;&nbsp;Equal<br>'''!=''' &nbsp;&nbsp;&nbsp;Not equal<br><br>
# Issue the following linux command to display display the car make, model number, quantity and price of all vehicles that are prices less than $5,000:<br><span style="color:blue;font-weight:bold;font-family:courier;">awk '$5 < 5000 {print $1,$2,$4,$5}' cars.txt</span><br><br>What do you notice?<br><br># Issue the following linux command to display display the car make, model number, quantity and price of all vehicles that are prices less than $5,000:<br><span style="color:blue;font-weight:bold;font-family:courier;">awk '$5 < 5000 {print $1,$2,$4,$5}' cars.txt</span><br><br>The symbol tilde '''~''' is used to match a pattern for a particular field number.<br><br># Issue the following linux command to display the car make, year and quantityof all car makes that begin with the letter "f":<br><span style="color:blue;font-weight:bold;font-family:courier;">awk '$1 ~ /^f/ {print $1,$2,$4}' cars.txt</span><br><br>
# x
13,420
edits

Navigation menu