Find and delete a certain HEX and its following value in a file

Hello there,

I've been trying to do this half of the day and it's like I haven't come a single step further, so I hope you guys can help me with my problem:

I have a text file that contains strings that should not be there and which I want to delete automatically from the command line. The character string always consists of two characters, beginning with the hex value "01" (e. g."01 90").

My task is therefore:"search for HEX value 01 and delete this and the following HEX-value". However, I'm too stupid for this task...

Can anyone help me or give me a suggestion which command I need? I've tried tr and sed so far..

Welcome to the forum.

A bit more information would be great, particularly an input sample, or, for your special problem, a hexdump ( od -tx1c file ) of it. And, your attempts, even though they failed, for analysis and discussion.

You can try:

LC_ALL=C sed "s/[\x01].//g" text_file > fixed_text_file

Testing example:

$ printf "Test:%b%b\n" "\x1" "\x90" | od -c
0000000   T   e   s   t   : 001 220  \n
0000010

$ printf "Test:%b%b\n" "\x1" "\x90" | LC_ALL=C sed "s/[\x01].//g" | od -c
0000000   T   e   s   t   :  \n
0000006
1 Like

Thanks, Chubler_XL. The example with sed didn't work (nothing happened actually), however, with perl it worked. So the final code was:

perl -pe "s/[\x01].//g" < text_file > fixed_text_file

Thank you very much :slight_smile:

sed -r 's/\b01\s+[0-9]{2}//g' YourFile