Im trying to replace the ProductName held inside a Visual Studio setup project by performing a regex on the file in my msbuild script. To do the regEx replacement Im trying to use msbuild extension pack and in particular its File task. The target inside my msbuild script looks like this:
<Target Name="CustomiseMsi">
<PropertyGroup>
<RegExPattern>
<![CDATA[(?:\""ProductName\"" = \""8:.*)]]>
</RegExPattern>
<RegExReplacement>
<![CDATA["\"ProductName\" = \"8:MyApp v1.0\""]]>
</RegExReplacement>
<RegExOutput></RegExOutput>
</PropertyGroup>
<MSBuild.ExtensionPack.FileSystem.File
TaskAction="Replace"
RegexPattern="$(RegExPattern)"
Replacement="$(RegExReplacement)"
Files="#(AbsolutePathToVdProjToParse)">
</MSBuild.ExtensionPack.FileSystem.File></Target>
When this target runs I get the following output, but the file remains unchanged.
CustomiseMsi:
Processing File Collection
Processing File: C:\pathHere\mySetup.vdproj
Am I going about this right way? Has anyone done regex updated on a vdproj (or anything else) in this manner?
I had this same issue and after trying a few things, I got this to work...
<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace"
TextEncoding="ASCII" RegexPattern='"ProductVersion" = "8:.*"'
Replacement='"ProductVersion" = "8:$(Version)"'
Files="%(Solution.DeploymentProject)"/>
This will simply replace the ProductVersion string with the version that I have in my Solution.DeploymentProject variable.
I dont believe you need to mess with CDATA at all.
Related
I have a code that I am trying to Package and Build on Visual Studio. It looks something like below
XSL to WXS (WiX packaging)
<wix:ServiceInstall Id="abc" Type="xyx" Account="mno" Password="Q.-[Je~m}12%#RT#"
While building, because of the special characters in the Password column, facing error - ICE03: Invalid format string
I tried to wrap the special characters within blocks []. But of no help.
Also tried placing "" at the beginning of the password value, but still the same error
Any suggestions are appreciated
I looked for an applescript to extract the DOI from a PDF file, but could not find it. There is enough information available on the actual format of the DOI (i.e. the regular expression), but how could I use this to get the identifier from the PDF file?
(It would be no problem if some external program were used, such as Hazel.)
If you're ok with using an app, I'd recommend Skim. Good AppleScript support. I'd probably structure it like this (especially if the document might be large):
set DOIFound to false
tell application "Skim"
set pp to pages of document 1
repeat with p in pp
set t to text of p
--look for DOI and set DOIFound to true
if DOIFound then exit repeat--if it's not found then use url?
end repeat
end tell
I'm assuming a DOI would always exist on one page (not spread out to between two). Looks like they are invariably (?) on the first page of an article, which would make this quick of course, even with a large doc.
[edit]
Another way would be to get the Xpdf OSX binaries from http://www.foolabs.com/xpdf/download.html and use pdftotext in the command line (just tested this; it works well) and parse the text using AppleScript. If you want to stay in AppleScript, you can do something like:
do shell script "path/to/pdftotext 'path/to/pdf/file.pdf'"
which would output a file in the same directory with a txt file extension -- you parse that for DOI.
Have you tried it with pdfgrep? It works really well in commmandline
pdfgrep -n --max-count 1 --include "*.pdf" "DOI"
i have no idea to build an apple script though, but i would be interested in one also. so that if i drop a pdf into that folder it just automatically extracts the DOI and renames the file with the DOI in the filename.
I was wondering if anyone could help me perhaps write a relatively simple batch file command that I can use to base the rest of my batch file off of. I work in a support group that supports many products and there is one in specific that I am the only one that understands the XML config files. What I am trying to do is the following:
Here is an excerpt from the config file:
<!-- FILEDROP SETTINGS -->
<!-- metadataType = X - XML; F - Flat file; E - embedded in filename; B - embedded PDF with bookmarks -->
<add key="metadataType" value="E" />
What I am trying to do is to create some GUI (batch file) that a user can run. Upon running the batch file, a user would be prompted to enter the name of the file to search for. In this example, the file name is importer.config. I want the batch file to search for the string
<add key="metadataType" value="E" />
I would like for it to take the value in between the quotation marks "E" in this case and output something to the DOS window to let the user know, that this component uses Metadata embedded in file name. Of course, if the value is F, this component uses metadata from a flat file....i am just trying to spell it out to the user in laments turn instead of having the user search through this large large config file because they never seem to know where to look.
Anyone that can help would be a huge huge help as this would be a basis for the rest of my code to display values to users. I have thought that using regular expressions and FINDSTR may be the best but i have tried so many things and cant get it working
something like: (?<=<add key="metadataType" value=")\w
This would look for the string i need and then take the value that follows (E in this case)...I just dont know how to write out where to store this or how to output it to something different....any help would be appreciated!
The regex support for FINDSTR is severely limited, and what is there does not work like what you are used to in traditional implementations. Read the documentation by typing help findstr or findstr /? from the command window. I also recommend reading What are the undocumented features and limitations of the Windows FINDSTR command?. The description of the regex oddities are toward the bottom of the answer.
You could download and use a Windows version of something like awk, grep, sed or perl. Or you could use VBScript or JScript.
Parsing XML with native batch is a nightmare. You could try something like the following. It is not very robust, but it will work in most cases:
#echo off
setlocal enableDelayedExpansion
for /f "delims=" %%A in ('findstr /rc:"\<add key=[\"\"]metadataType[\"\"] value=[\"\"]" "fileName.txt"') do set "ln=%%A"
set ^"ln=!ln:*"metadataType" value=!"
for /f delims^=^=^" %%A in ("!ln!") do set value=%%A
echo value=!value!
im experimenting in getting camel to do some file operations and pass them through the activeMQ broker, ive taken this project over from a guy who recently quit.
what ive got so far:
<route id="SVLFTPCOPY">
<from uri="sftp://*****:*******#********/srv/test/?fileName=*2280.xls&noop=true&idempotent=false"/>
<to uri="file:/srv/data/test/destination/"/>
<to uri="activemq:queue:svl.ftp.copy"/>
</route>
it works to the point where it runs the route without throwing any errors, but still doesnt copy the file to the local file.
Any ideas?
.
Yeah you need to use the include/exclude/filter option if you want to filter out files based on patterns. The fileName option is for a single file.
So in your case, remove fileName option and replace it with include=.*2280.xsl. Mind that the include is based on Java regular expressions, so we use dot star to indicate wildcard. More details here: https://camel.apache.org/components/latest/file-component.html. The ftp component inherits 99% of the options of the file component, so that is why I refer to the file wiki page.
Use the include option that uses Java regular expression:
include=.*2280\\.xsl
Please, mind the \\ before the dot .
Alternatively, use antInclude:
antInclude=*2280.xsl
For that kind of filtering I recommend to use the GenericFileFilter
In the implementation of name matching, the following code is used:
if (ObjectHelper.isNotEmpty(endpoint.getInclude())) {
if (!name.matches(endpoint.getInclude())) {
return false;
}
}
So you can test which regular expression you should use. In you case, I think .*2280\\.xsl is what you should use.
I have various projects that had files with SVN history in them. I recently moved those projects to a Mercurial repository so now that history within the file is useless. Is there a way to remove those which is not by hand?
Here's an example:
/*
* $Rev:x$
* $LastChangedDate:x$
* $LastChangedBy:x$
*/
Where x is a value in the files. I assume some sort of regex would help. Any idea?
Edit:
This is the working answer:
<target name="remove-svn-history">
<replaceregexp byline="false" match="\A/\*.*?\*/" replace="">
<fileset dir="src" includes="**/*.java"/>
</replaceregexp>
</target>
Assuming that's at the beginning of the file, you could match it with the following regex:
\A/\*.*?\*/