Example: test.txt
hello:../../Need/script/hello/123/234
hello:../../../../Need/script/hello/123/468
hello:../Need/Script/hello/123/789
Need to replace between "hello" words with this string: ":D:/test/testing/tester/"
Output: test.txt
hello:D:/test/testing/tester/hello/123/234
hello:D:/test/testing/tester/hello/123/468
hello:D:/test/testing/tester/hello/123/789
Tried something like below script but got java error.
<replaceregexp file="./test.txt"
match="hello**hello"
replace="hello:D:/test/testing/tester/hello"
byline="true"/>
Error:
D:\Others\anttest\build.xml:7: java.util.regex.PatternSyntaxException: Dangling
meta character '*' near index 6
hello**hello
^
at java.util.regex.Pattern.error(Pattern.java:1924)
at java.util.regex.Pattern.sequence(Pattern.java:2090)
at java.util.regex.Pattern.expr(Pattern.java:1964)
at java.util.regex.Pattern.compile(Pattern.java:1665)
at java.util.regex.Pattern.<init>(Pattern.java:1337)
Related
I am having trouble knitting a pdf document with RMarkdown when embedding images. When using the markdown syntax below:
![Image name](~/folder/folder/filename.png)
I get the error:
Package pdftex.def Error: File `~/folder/folder/filename.png' not found: using draft setting.
I have also tried:
``` {r results = 'asis'}
knitr::include_graphics(path = "~/folder/folder/filename.png")
```
And, I get the error:
Unescaped left brace in regex is passed through in regex; marked by <-- HERE in m//\nobreakspace { <-- HERE }/folder/folder/filename/ at C:\Users\NAME~1\AppData\Roaming\TinyTeX\texmf-dist\scripts\texlive\tlmgr.pl line 1847.
Error in grep(paste0("/", x[j], "$"), l) :
invalid regular expression '/\nobreakspace {}/folder/folder/filename$', reason 'Invalid contents of {}'
Calls: ... system2_quiet -> on_error -> parse_packages -> grep
In addition: Warning message:
In grep(paste0("/", x[j], "$"), l) :
TRE pattern compilation error 'Invalid contents of {}'
Warning: LaTeX Warning: Reference `LastPage' on page 1 undefined on input line 153.
Execution halted
I have tinytex installed, but maybe I am missing another LaTeX package? Any guidance would be appreciated.
First, as #samcarter_is_at_topanswers.xyz recommended above, the tilde character cannot be interpreted from Markdown to LaTeX.
Additionally, I had my markdown file in one subfolder and my images in another subfolder. When I was knitting the markdown file, the working directory changes to the subfolder that the markdown file is in causing the file path provided for the images to no longer be understood when using the path folder/folder/filename.png. You can either move the markdown file to the main directory or set the entire file path.
If you move the markdown file to the main directory the file path can look like:
![Image name](folder/folder/filename.png)
or keep in the subfolder and use:
![Image name](entire path/folder/folder/filename.png)
The same goes for using knitr's include_graphics function.
I am using the Pipeline Utility Steps to read and updated the yaml files in my repo. However there is one key (chart-name) which has "-" (not "_", I know this is not preferred but its there). Now the problem i am facing is that "-" is considered as "binary expression" and its giving the error.
'''
script {
def filename = "values.yaml"
def data = readYaml file: filename
data.chart-name.image.image = "imange name"
sh "rm $filename"
writeYaml file: filename, data: data
}
'''
Error:
(data.chart - name.image.ports.containerPort) is a binary expression, but it should be a variable expression at line: 96 column: 51. File: WorkflowScript # line 96, column 51.
name.image.ports.containerPort = "${param
You can use the quotation syntax for accessing Map-like objects in Groovy, e.g.:
data.'chart-name'.image.image = "image name"
Of course, you might want to make sure nothing on that chain returns a null value...
I was trying to read a .txt file using lua in command prompt, I'm using 'Lua For Windows' but in the way I tried it's not working, it don't give me any error, it don't return anything, not even 'nil'.
I tried this:
file = io.open("C:\Users\user\Desktop\a.txt", "r") --(and my user's name)
io.input(file)
print(io.read())
io.close(file)
The backslash is an escape character in Lua quoted strings.
Try "C:\\Users\\user\\Desktop\\a.txt".
Or avoid the issue using long strings: [[C:\Users\user\Desktop\a.txt]].
I looped in the directory tree of a "content" folder containing subdirectories and markdown files. Then I need to know the relative path of those markdowns from that "content" folder.
In bash script I would do something like that :
CONTENT_PATH="/home/myusr/apps/myapp/content"
file_path="/home/myusr/apps/myapp/content/file/pgp.md"
echo "${file_path#$CONTENT_PATH}"
# /file/pgp.md
So in Lua I didn't found something like that, so I've tried with string.gsub():
print(string.gsub(file_path, CONTENT_PATH, ""))
-- /home/myusr/apps/myapp/content/file/pgp.md 0
But it's not working, it seems my CONTENT_PATH string does not match and I don't know why?
print(CONTENT_PATH)
-- /home/hs0ucy/_01_http/fakestache-lua/content
print(file_path)
-- /home/hs0ucy/_01_http/fakestache-lua/content/file/pgp.md
Thanks!
PS : I'm new to Lua.
From: Lua string.gsub with a hyphen
The hyphen is a special character in Lua, and needs to be escaped like so: %-.
I discovered this by slowly making CONTENT_PATH longer and longer until it was no longer working. Good ol' binary search!
EDIT: if you can't modify your CONTENT_PATH but you're sure that file_path has CONTENT_PATH in it:
contentPathLen = string.len(CONTENT_PATH)
print(string.sub(file_path, contentPathLen + 1))
-- Output: /file/pgp.md
Or if you need to verify that file_path starts with CONTENT_PATH:
base = string.sub(file_path, 0, contentPathLen)
if base == CONTENT_PATH then
print("file_path is under CONTENT_PATH")
end
I want to be able to encode a path for use as a url i.e change spaces to %20. I found this function which does the encoding:
urlencode() {
setopt localoptions extendedglob
input=( ${(s::)1} )
print ${(j::)input/(#b)([^A-Za-z0-9_.\!~*\'\(\)- ])/%${(l:2::0:)$(([##16]#match))}}
}
and want to be able to pass the results of this:
print -l $PWD/* | tail -1
to the function.i.e get the last full path in the file list and encode it.
I thought that something like this:
print -l $PWD/* | tail -1 | urlencode
or
print -l $PWD/* | tail -1 > urlencode
would work but they don't.
Does anyone know how to accomplish it?
Many Thanks
You need to get your input from stdin rather than from the first argument.
Here is one way to adapt the function to do this
urlencode() {
setopt localoptions extendedglob
stdin=`while read line; do echo $line ;done`
input=( ${(s::)stdin} )
print ${(j::)input/(#b)([^A-Za-z0-9_.\!~*\'\(\)- ])/%${(l:2::0:)$(([##16]#match))}}
}
I tested it on my terminal, it works