I have been using strings to extract and compare file versions between directories.

I don't seem to be able to do this recursively.

The method I have been using per file is:

strings -e l FILENAME.exe | sed -e :a -e '/FileVersion$/N; s/FileVersion\n/FileVersion /; ta' | grep FileVersion | cut -d ' ' -f 2

Removing Filename and replacing with * works. But I only get File version and no filename. Including a -F give me the filename for strings.

But I don't understand how I can format Sed / Grep to collect just the Filename and Version Number.

  • Or if i use: strings -f -e l *.exe | sed -e :a -e '/FileVersion$/N; s/FileVersion\n/FileVersion /; ta' | grep FileVersion This works, But its formatted like: report10.exe: FileVersion report10.exe: Anyway to remove the Second filename before the version number So it would look like: report10.exe: FileVersion: Or report10.exe: – Dave Hamilton Mar 11 '16 at 16:48

This was just bad understanding with the use of cut and sed.

Slight tweak to the one liner:

strings -f -e l *.exe | sed -e :a -e '/FileVersion$/N; s/FileVersion\n/FileVersion /; ta' | grep FileVersion | sed 's/.*FileVersion//'

So string uses -f for filename, -e for necessary file info.

sed is used to strip and leave the Fileversion

Then grep to locate that info to Screen

then one last sed to remove Content before Fileversion (This is not a proper way to do it, I find understanding sed's patterns complicated)

sed 's/.*FileVersion//'

If someone wants to post the correct formatting for sed, I'll happily update this. Unfortually the Patterns and understanding of sed don't quite sink in properly.

  • You could use sed -n so it does not output anything but what you want it to with the print "p" – Rob Mar 11 '16 at 17:07

Sounds like you want to print the lines following those that end in FileVersion, so it should just be a matter of:

strings -f -e l -- *.exe | sed -n '/FileVersion$/{n;p;}'

You could just do something like:

 strings -e l -f FILENAME.exe | sed -n -e :a -e '/FileVersion$/,/.*/{/FileVersion$/d;/.*/p}'

This will have sed not print any line "-n" except the line you tell it with p. Then you tell it to find a line that ends with FileVersion and the next pattern since the end pattern is .* it will match the next line :). You then tell it to delete the FileVersion line and print the rest which will contain your verion :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.