At the risk of showing my ignorance...:-)
I have several files that have "binary glop" in them --
with a buried absolute, ascii, pathname in them. I wish to search for a specific filename (the 'basename' in the pathhname) and have the embedded pathname printed out.
The files are win-style .lnk files that lost their "mojo" under cygwin and appear as regular files like "aclocal.lnk".
The correct targets are embedded in the .lnk files (in posix format & dos format, but am ignoring the dospath).
Example file:
<binary>/etc/alternatives/aclocal<binary>C:\etc\alternatives\aclocal<e
+of>
The string is searchable with grep which displays the binary garbage before and after with.
My first attempt was to read in the file on stdin, and search for my target and use patterns before and after to
display the entire path like:
$pathchrs => '[-\/\.[:alnum:]_]';
$target = 'aclocal'
while(<>){
/(\/$pathchrs*$target$path*)/o && print "$1\n";
}
Unfortunately, life was not so simple. Even though the pattern works under "grep":
grep -a '/[-\/\.[:alnum:]_]*aclocal[-\/\.[:alnum:]_]*' /bin/aclocal
+.lnk
perl (and pcregrep) don't seem to find it.
FWIW - I made it work by splitting input into a buffer and removing non-printables, but that's hardly an efficient use of perl.
Why didn't the simpler approach work?
Thanks for perls of wisdom...:-)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.