How to remove “binary data” from a text file (e.g. bash_history)

binarygrep

Like discussed in questions like:

that grep might stop processing files it considers binary.

While this is normaly not a big problem, when searching text files, it has turned out, that sometimes some text files are "dirty", i.e. contain some binary data.

My specific case motivating this question is that somehow some binary data (to whatever is considered binary by grep, see questions cited), made its way into the .bash_history file, I would like to remove it.

How can I remove binary data from a text file?

More than just the removing binary data, I would appreciate to be able to have a look on what is the offending (to grep) binary data, as to avoid the removal of something needed/important.

Best Answer

cat -v .bash_history > newbashhistory

Look at newbashhistory and decide if you like it