Skip to Content
Mastering Linux Shell Scripting - Second Edition
book

Mastering Linux Shell Scripting - Second Edition

by Mokhtar Ebrahim, Andrew Mallett
April 2018
Beginner
284 pages
7h 3m
English
Packt Publishing
Content preview from Mastering Linux Shell Scripting - Second Edition

Displaying and filtering content from files

Now, of course we all want to be able to print a little more than just Hello World. The awk command can be used to filter content from files and, if needed, very large files. We should begin by printing the complete file before filtering it. In this way, we will get a feel for the syntax of the command. Later, we will see how we can add this control information into awk files to ease the command line. Using the following command, we will print all the lines from the /etc/passwd file:

$ awk ' { print } ' /etc/passwd  

This is equivalent to using the $0 variable with the print statement:

$ awk ' { print $0 }' /etc/passwd 

AWK provides us with some ready-to-use variables to extract data such as:

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting - Second Edition

Learning Linux Shell Scripting - Second Edition

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788990554Supplemental Content