Extracting specific columns when your delimiter is a mess
Text Processing (Grep/Sed/Awk)
Extracting specific columns when your delimiter is a mess
🧩 The Challenge
Dealing with logs or configuration files where the spacing is inconsistent—like one tab here, three spaces there—is a nightmare. You try to cut by a field index and end up with empty strings or garbage data because the formatting isn’t uniform.
💡 The Fix
Use awk without a specific field separator to treat any sequence of whitespace as a single delimiter. It saves you from writing complex regex to normalize the file first.
awk '{print $2, $5}' your_messy_log.txt
⚙️ Why It Works
By default, awk splits input lines using any number of spaces or tabs as a single delimiter, which handles those messy, inconsistent logs automatically. It skips leading and trailing whitespace too, which is a nice bonus.
🚀 Pro-Tip: If you need to print a separator like a comma between the fields, set the output field separator variable with -v OFS=’,’.
Linux Tips & Tricks | © ngelinux.com | 9/10/2026
