Skip to content
Clairos Learn

Text and logs · Lesson 17 of 38 · 8 minutes

Awk column extraction

Use awk to pull simple columns from logs.

Mastery 0/3Run itExplain itApply it
learner@clairosSimulated Linux lab
learner@clairos:~ $
↑ history · Tab complete · Ctrl+C cancel · Esc, Tab to leaveExit 0

Understand the pattern

Junior operators build confidence by gathering evidence before changing systems.

awk
Extract whitespace-delimited fields with the supported print patterns.

Quote awk programs so shell variable expansion does not consume $1; single quotes are usually appropriate.

journalctl
Read the training journal by unit or a bounded line window.

A relevant unit and time range are more useful than an unfiltered wall of logs.

Worked example and expected result
$ awk '{print $1}' /var/log/auth.log
May
May
May
May

Exit status: 0. The command completed successfully in the training fixture.

$ awk '{print $5}' /var/log/auth.log
sshd[104]:
sshd[118]:
sudo[126]:
sshd[141]:

Exit status: 0. The command completed successfully in the training fixture.

$ journalctl -u ssh | awk '{print $5}'
sshd[104]:
sshd[118]:
sshd[141]:

Exit status: 0. The command completed successfully in the training fixture.

Try a variation

Repeat this workflow in the sandbox with a different scratch filename. Keep the system fixtures unchanged and compare the observed output with your expectation before moving on.

Explain it

In “Awk column extraction”, which interpretation is safe?

Apply it elsewhere

Before adapting the awk workflow from “Awk column extraction” to another server, what should you do?

Keep the momentum.

Complete the lab, then explain and apply the pattern.

Next: Cut field selectionTry an incident drill

Anonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.

Keep learning

  1. 01Sed substitutionPreview text replacement without editing a log.Practice
  2. 02Cut field selectionExtract colon-delimited identity fields.Practice
  3. 03Text case transformsTransform piped text with tr.Practice