Text Processing (Grep/Sed/Awk)
Stop parsing fixed-width logs the hard way
🧩 The Challenge
Dealing with those ancient legacy application logs that don’t use tabs or JSON is a total nightmare. I spent three hours yesterday trying to align columns by eye before I remembered there is a much saner way.
💡 The Fix
Use awk to print specific column ranges based on character position rather than whitespace. It saves you from writing complex regex patterns that break the second a log entry format changes slightly.
awk '{print substr($0, 1, 10), substr($0, 25, 15)}' legacy_app.log
⚙️ Why It Works
Setting the start position and the length in the substr function lets you carve up a line like a sandwich, ignoring whether there are three spaces or thirty in between fields. It is a lifesaver when the log file layout is as rigid as a brick wall.
🚀 Pro-Tip: Pipe this into sort -u if you are trying to find unique combinations of fields in a massive, messy file.
Linux Tips & Tricks | © ngelinux.com | 9/13/2026
