Another good grep trick to find strings that end in numbers but you are not sure which.

Posted: December 26, 2012. At: 2:29 PM. This was 5 years ago. Post ID: 5067

How do you search a binary file for a certain string that ends in a number; but you are not sure what the number is? Then this command will perform this task.

[email protected] ~/Documents/master $ strings vesperas.wad | grep -a "MAP[0-9]"

I was using this command as I had a folder full of Doom wadfiles and I could use this to see what level number they were to play them. This shows how flexible and useful the BASH shell is.

Here is another example with ls.

[email protected] ~/Documents $ ls -hula time[0-9].c
-rw-r--r-- 1 john john 802 Oct  7  2011 time3.c

This example below shows that you can couple wildcards with this technique to display a listing of the files that you are after.

[email protected] /mnt/Elements/Wallpapers $ ls -hula space-[0-9]*
-rwxrwxrwx 1 root root 74K Nov 26  2011 space-01.jpg
-rwxrwxrwx 1 root root 82K Dec 29  2011 space-02.jpg
-rwxrwxrwx 1 root root 31K Dec 29  2011 space-03.jpg
-rwxrwxrwx 1 root root 77K Dec 29  2011 space-04.jpg
-rwxrwxrwx 1 root root 15K Dec 29  2011 space-05.jpg

As you can see, this is one useful technique that could come in handy when you are searching a folder with a heap of files for one or two that match certain criteria. Very useful indeed.

No comments have been made. Use this form to start the conversation :)

Leave a Reply