Posted: . At: 2:29 PM. This was 11 years ago. Post ID: 5067
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


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


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.

john@adeptus-mechanicus ~/Documents/master $ strings vesperas.wad | grep -a "MAP[0-9]"
MAP15

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.

john@adeptus-mechanicus ~/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.

john@adeptus-mechanicus /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.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.