A coworker (on MS Windows) was cursing he couldn't see what symbol names might be hidden in a non-text configuration file for a proprietary, 3rd party tool he has to use. Since I didn't want to risk being constantly asked to "dump symbols" using my Lunix system, I took a few minutes to write the following program in Perl. Made him happy (for now, at least).

Note: The tool being used only supports ASCII characters, so I didn't bother with encodings. Probably didn't need to specify ":bytes" in the open statement, but no harm in doing so.

Maybe others will find this useful.

#!perl use 5.010_000; use warnings; use strict; if ((@ARGV < 1)) { $0 =~ m#([^\\/]+$)#; my $name = $1 // $0; print STDERR "$name file ...\n" . <<'_DESCRIPTION_'; Extract ASCII strings from files listed. Multiple files allowed. _DESCRIPTION_ exit 1; } for my $file (@ARGV) { open my $fh, '<:bytes', $file or die "Error: Can't open '$file': $ +!\n"; my $buf; while (read $fh, $buf, 1024) { my @strings = split /\P{PosixGraph}/, $buf; for (@strings) { next if /^\s*$/; print "$_\n"; } } }

Replies are listed 'Best First'.
Re: extracting strings from non-text files
by soonix (Chancellor) on Oct 21, 2016 at 07:08 UTC

      ppt and PerlPowerTools both had dependency issues (yes, I tried cpan ppt and cpan PerlPowerTools) that I didn't want to mess with. After that, didn't think about the alternatives, was just easier to cough up the simple program I did.

Re: extracting strings from non-text files
by kschwab (Vicar) on Dec 20, 2016 at 20:32 UTC

    Nice quick and dirty approach, but you're likely missing things that cross the boundary of your 1024 byte buffer.

    This node has a couple of replies with examples of using a sliding window to find strings in a binary file.