Sample Header Ad - 728x90

How to grep contents in HEX specifying the pattern in decimals?

0 votes
1 answer
663 views
I have a file with the following contents (as a text file in UTF-8)
e04ba1af81d887979ddcee1dc23f2531
43f85926fdb6a668386ee354f8b836a1
b53614f5139c052ec08ea1ecd2532daf
e9b3914d7b1e1bf8e6feab621330245b
bbcad02116316176385fbfb294ee77b4
I need to ensure that this file contains a number 46390 (decimal). It equals b536 in HEX that is the beginning of the 3rd line. How do I use grep or awk to make it convert both file and pattern to binary representation and then do a search? In other words, make searching base independent considering that bases are known. Sample output: 1)
$ cat file.txt | grep 46390
**1011010100110110**1010011110101000100111001110000000101001011101100000010001110101000011110110011010010010100110010110110101111 (it's **b536**14f5139c052ec08ea1ecd2532daf in hex) 2) A file contains a single string 3CA547A (binary 0011110010100101010001111010). I am given a decimal representation of some sequence. The file may contain this sequence and it may be not aligned by 8 bits. Let's assume this sequence is equal to decimal 15 (binary 1111) The command:
$ cat file.text | grep 15
The result would contain 2 occurrences: 00**1111**001010010101000**1111**010
Asked by Enbugger (109 rep)
Aug 28, 2019, 02:11 AM
Last activity: Aug 28, 2019, 05:49 PM