Norfeldt
Norfeldt

Reputation: 9678

Piping python script print out with sed (removing ansi colors) and writing it to a file

I'm trying to both see the colorful print out in my python script and writing it to a file without the ansi colors at the same time.

This seems to working fine for me (only save it to a file):

$python3 utils/search.py 'Magnesiumstearat' './PROCESSED/md/tablet/2020-08-04/' | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' > results.txt

I don't see the print - it only writes to the file?

(Using macOS if it matters - but need it to work on a Linux (raspberry pi) as well)

Upvotes: 2

Views: 194

Answers (1)

Norfeldt
Norfeldt

Reputation: 9678

found the solution to be

python3 utils/search.py 'Magnesiumstearat' './PROCESSED/md/tablet/2020-08-04/' | tee /dev/stderr |sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' > results.txt

Thanks @Kusalananda https://unix.stackexchange.com/a/528333/390853

Upvotes: 1

Related Questions