Text Processing (Grep/Sed/Awk)
Stop awk from truncating your output when fields have spaces
🧩 The Challenge
Dealing with CSV files that have spaces inside quoted fields is a nightmare. I’ve spent way too much time cleaning up data only to realize awk split my columns right in the middle of a user’s name.
💡 The Fix
Use the FPAT variable instead of the default field separator. It lets you define fields by regex patterns so you can ignore the delimiters hiding inside quotes.
awk -v FPAT='([^,]*)|("[^"]*")' '{print $2, $4}' data.csv
⚙️ Why It Works
Setting FPAT tells awk to treat anything matching the regex as a field, which handles those annoying embedded commas perfectly. You stop fighting the delimiter and start letting the pattern do the heavy lifting.
🚀 Pro-Tip: If your CSV uses tabs or weird pipes, just swap the regex inside FPAT to match the new structure without rewriting your entire print logic.
Linux Tips & Tricks | © ngelinux.com | 8/18/2026
