To port a GNU makefile to the (non-cygwin) win32 platform, I am looking for a way to scan source files for the patterns such as '1234 // $RESOURCE$ "my_image.ico"', to then be appended to a resource file in the format '1234 ICON "my_image.ico"'. Using perl this is can be accomplished as such:
perl -nle 'print "$1 ICON $2" if /([0-9]+)\s*\/\/\s*\$RESOURCE\$\s*(\".*\")\s*$$/'
On windows, the thing that just came close is findstr
, but this only allows for matching, not outputting in the alternative form. Simply replacing the string constant in between should do it I guess.
Any clues on how to get this going, short of includin开发者_如何学编程g my own perl/sed.exe in the distribution :)?
You could use VBScript (or even PowerShell, though that's still somewhat rare to be default), if you're not desperately in need of a cmd
solution.
I have a little trouble reading your regex here, but it looks like this (correct me if I'm wrong):
some-number // $RESOURCE$ ...something-else...
in which case you can couple findstr
with for /f
which can do tokenizing of the input:
for /f "usebackq tokens=1,2* delims=/ " %%a in (`findstr ... file`) do echo %%a ICON %%c
where %%c
would be the third (and last) token (with delimiters being space and /
) and %%a
the first one.
I have no clue of Perl so this is a lot of guessing right now. Quick test:
> for /f "usebackq tokens=1,2* delims=/ " %a in ('123 // $RESOURCE$ abc def') do @echo %a ICON %c
123 ICON abc def
The 2*
in the tokens
option above will cause everything from the third token to be included, regardless of whether it has delimiting characters or not.
Hope this helps (a little at least).
精彩评论