You are here:About>Computing & Technology>Focus on Linux
About.comFocus on Linux
awk Command <Linux Glossary>

Related Terms
grep Command
Definition: awk is a powful Unix command. It allows the user to manipulate files that are structured as columns of data and strings.

Once you understand the basics of awk you will find that it is surprisingly useful. You can use it to automate things in ways you have never thought about. It can be used for data processing and for automating the application of Unix commands. It also has many spreadsheet-type functionalities.

There are two ways to run awk. A simple awk command can be run from the command line. More complex tasks should be written as awk programs ("scripts") to a file. Examples of each are provided below.

Example: % awk 'pattern {action}' input-file > output-file

meaning: take each line of the input file; if the line contains the pattern apply the action to the line and write the resulting line to the output-file.

If the pattern is omitted, the action is applied to all lines:

% awk '{action}' input-file > output-file

By default, awk works on files that have columns of numbers or strings that are separated by white space (tabs or spaces), but the -F option can be used if the columns are separated by another character. awk refers to the first column as $1, the second column as $2, etc. The whole line referred to as $0.

Related Resources:

Command Library
Unix commands are introducted one by one, with examples.

<Linux Glossary>
From Juergen Haas,
Your Guide to Focus on Linux.
FREE Newsletter. Sign Up Now!
Newsletters & RSSEmail to a friendSubmit to Digg
 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.