Text Processing (Grep/Sed/Awk)
Stop manually stripping junk from your log exports
🧩 The Challenge
Dealing with raw logs that contain non-printable garbage or weird ANSI color codes is a total nightmare when you are trying to grep for errors. I once spent forty minutes trying to match a string that was literally invisible because of some stray terminal escape codes.
💡 The Fix
Use sed to strip those ANSI color codes out of your text stream before they ever touch your grep or your eyes. It saves your sanity when you are staring at log files piped from a weird legacy appliance.
sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" input.log | grep "ERROR"
⚙️ Why It Works
Regex matching on the escape character hex code kills the control sequence entirely so your output becomes plain, searchable text. It’s a clean way to clean up logs on the fly without changing the source file on disk.
🚀 Pro-Tip: Stick this in a function in your .bashrc and stop typing the full hex sequence every single time.
Linux Tips & Tricks | © ngelinux.com | 9/28/2026
