Unix Tip: Sed & Awk -- Still friendly after all these years | Linux Today

Unix Tip: Sed & Awk — Still friendly after all these years

Written By
SH
Sandra Henry-Stocker
Mar 12, 2010

“Even after decades of using Unix on thousands of systems, I
find that it’s still fun to discover various convolutions of sed
and awk commands to perform command line wizardry. There’s a lot
more to each of these tools than those uses I make of these
commands on a routine basis. Let’s take a look at some one-liners
you might not yet have tried.

“One of my long-standing “tricks” for awk is using $NF to print
the last field on every line. Since NF represents the number of
fields on a line (e.g., 6), $NF represents the value of that last
field (e.g., $6). Printing the last field of every line, therefore,
might look like this:

$ awk ‘{print $NF}’ myfile

“or this:

$ awk -F: ‘{print $NF}’ /etc/passwd

“depending on whether the file is white space delimited or
not.”


Complete Story

SH

Sandra Henry-Stocker

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.