Colored output breaks pipes

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-03-28

I could not get a substitution of some backslashes working in sed in this pipe:

i.e. the data was

episodes/ep-25.mp4
episodes/ep-26.mp4

I ran this command:

cat /tmp/data.json | jq -M ".Contents [] .Key" | rg "episodes" | sed 1d | gsed "s/episodes\///"

But the output was the same as the input. Removing the backslash in sed got it to work. Somehow my reference to backslash was not working.

After thinking about it, I noticed that rg had highlighted in color the bit it matched episodes Therefore there were escape characters breaking sed's matching. Once I disabled rg color, things worked fine.

cat /tmp/data.json | jq -M ".Contents [] .Key" | rg "episodes" --color never | sed 1d | gsed "s/episodes\///"