Stop parsing fixed-width logs with your eyes

Text Processing (Grep/Sed/Awk)

Stop parsing fixed-width logs with your eyes

🧩 The Challenge

Dealing with those ancient log files where every field is aligned with spaces instead of delimiters is pure misery. Trying to eyeball column seven when you’re staring at a terminal at 2 AM is a one-way ticket to a headache.

💡 The Fix

Use awk’s fixed-field support to slice those lines into manageable pieces based on character positions. You’ll save your sanity and stop accidentally grabbing the wrong data.

awk 'BEGIN { FIELDWIDTHS = "10 5 20 *" } { print $2, $4 }' logs.txt

⚙️ Why It Works

Setting the FIELDWIDTHS variable tells awk exactly where each column begins and ends, which forces it to treat the fixed-width mess like a clean, delimited file. It turns a nightmare of whitespace into something you can actually filter with standard tools.

🚀 Pro-Tip: Keep the field widths in a bash array if you’re doing this for multiple different log formats so you don’t have to manually count characters every single time.

Linux Tips & Tricks | © ngelinux.com | 7/17/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted