[SOLVED] Searching for a specific hex string or byte array in various images
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
David, I tried copying and pasting your given code against .jpg files. It works without any issues but for some weird reason it doesn't want to work on the .tif file format. When I try to use the codes given below it works without any issues and gives me what I want but without the String search count:
Code:
xxd -p /your/file | tr -d '\n' | grep -c '22081b00081f091d2733170d123f3114' WORKS FINE and returns 1 for a single .tif file. I tried on 400 .tif files too and it works without any issues and returns me 1 each time.
and,
awk '{/\x00\x02\x13\x12\x30\x44/ {print FILENAME ; exit}' $f WORKS FINE too and returns the full .tif file locations for all the available .tif files in that specific directory.
What might be possibly wrong? I am 100% certain that the string I am using is a genuine one and is found inside all the 400 .tif files.
Thank you for that awesome innovative code. It worked without any issues but for some unknown reason its giving me a count of 1 instead of 400 again. Is there any chance of piping the output of xxd to wc as @syg00 is suggesting. Thank you @syg00 for that comment. Could you please demostrate by giving us a command for it, please.
Why not use -l (L lowercase) switch for grep, you save a loop
Code:
grep -l -P '\x22\x08\x1b\x00' /FILEPATH/* | wc -l
Thanks, keefaz for your code. It works without any issues. Any ideas for adding echo "Something Here" command inside a loop especially inside the code given below, please. I can't do it for some reason. Also, is it possible to add echo command after done and before the pipe?
Code:
#!/bin/bash
files=/FILEPATH/*
for f in $files
do
# Watch byte order. To grep for 22081b00:
grep -m 1 -P '\x22\x08\x1b\x00' < "$f"
done | wc -l
If you add any echo line before the wc -l pipe, you'll end with wrong count at output, wc will count also your echo lines
Or maybe redirect echo output to standard error
As for putting a command between the done and the wc pipe, it won't work, you'll break link with output from the loop and wc pipe input.
Code:
for f in $files
do
# Watch byte order. To grep for 22081b00:
grep -m 1 -P '\x22\x08\x1b\x00' < "$f"
echo "Something Here" >&2
done | wc -l
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.