Text Processing (Grep/Sed/Awk)
Stop picking columns by counting spaces
🧩 The Challenge
You know that feeling when you’re trying to pull a specific PID or interface name out of a command, but the column alignment shifts depending on the system load or the length of the process name? I’ve spent way too long counting spaces in columns while staring at `ps` output only to have the script break ten minutes later.
💡 The Fix
Start using AWK field separators instead of relying on fixed positions. It lets you treat those messy white-space outputs like a real database.
ps aux | awk 'NR>1 {print $2, $11}'
⚙️ Why It Works
Setting the default behavior allows AWK to treat any run of whitespace as a single delimiter. By ignoring the header line with NR>1, you grab exactly what you need without caring if the username field decided to get extra long that day.
🚀 Pro-Tip: Use -F if your data is actually delimited by commas or colons instead of spaces.
Linux Tips & Tricks | © ngelinux.com | 11/9/2026
