substitution

Non-sequential substitution in SymPy

余生颓废 提交于 2019-12-21 03:38:40
问题 I'm trying to use [SymPy][1] to substitute multiple terms in an expression at the same time. I tried the [subs function][2] with a dictionary as parameter, but found out that it substitutes sequentially. In : a.subs({a:b, b:c}) Out: c The problem is the first substitution resulted in a term that can be substituted by the second substitution, but it should not (for my cause). Any idea on how to perform the substitutions simultaneously, without them interfering with each other? Edit: This is a

Bash bad substitution with subshell and substring

蹲街弑〆低调 提交于 2019-12-21 03:19:18
问题 A contrived example... given FOO="/foo/bar/baz" this works (in bash) BAR=$(basename $FOO) # result is BAR="baz" BAZ=${BAR:0:1} # result is BAZ="b" this doesn't BAZ=${$(basename $FOO):0:1} # result is bad substitution My question is which rule causes this [subshell substitution] to evaluate incorrectly? And what is the correct way, if any, to do this in 1 hop? 回答1: First off, note that when you say this: BAR=$(basename $FOO) # result is BAR="baz" BAZ=${BAR:0:1} # result is BAZ="b" the first

Capture the number of 'yes' clicks in a substitute command with confirmation?

≯℡__Kan透↙ 提交于 2019-12-20 05:58:23
问题 Is it possible to capture the number of 'yes' clicks in a substitute command with confirmation? p.e. :%s/foo/bar/gc replace with bar (y/n/a/q/l/^E/^Y)? number of y clicks = ? 回答1: If you want to know how many substitutions were done (the number of y ), after all occurrences confirmation were asked, you will see X substitutusions on Y lines , the X is what you want. If you are writing a script and you want to get the number in your script. You can either implement this counter in your function

Whats the difference between {$var} and $var?

こ雲淡風輕ζ 提交于 2019-12-20 01:45:45
问题 I would like to know when and why should I use {$var} echo "This is a test using {$var}"; and when (and why) should I use the simple form $var echo "This is a test using $var"; 回答1: You would use the latter when a) not accessing an object or array for the value, and b) no characters follow the variable name that could possibly be interpreted as part of it. 回答2: http://php.net/manual/en/language.variables.variable.php In order to use variable variables with arrays, you have to resolve an

multiple regex substitution in multiple files using python [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-19 11:55:17
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I have one project where I need to apply a dozen or so regex to about 100 files using python. 4+ hours of searching the web for various combinations including "(merge|concatenate|stack|join|compile) multiple

deparse(substitute(x)) in lapply?

谁都会走 提交于 2019-12-18 12:13:31
问题 I would like use a function that uses the standard deparse(substitute(x)) trick within lapply . Unfortunately I just get the argument of the loop back. Here's my completely useless reproducible example: # some test data a <- 5 b <- 6 li <- list(a1=a,b2=b) # my test function tf <- function(obj){ nm <- deparse(substitute(obj)) res <- list(myName=nm) res } tf(a) #returns $myName [1] "a" which is fine. If I use lapply I either get [[1L]] or the x argument of an anonymous function. lapply(li

Command substitution within sed expression

有些话、适合烂在心里 提交于 2019-12-18 09:22:30
问题 I'm having little problem with bash/sed. I need to be able to use command substitution within sed expression. I have two big text files: first is logfile.txt which sometimes* shows error messages by ID (0xdeadbeef is common example) in format ERRORID:0xdeadbeef second errors.txt has error messages stored in pairs LONG_ERROR_DESCRIPTION, 0xdeadbeef I was trying to use sed with bash command substitution to do the task: cat logfile.txt | sed "s/ERRORID:\(0x[0-9a-f]*\)/ERROR:$(cat errors.txt |

Bash variable substitution on find's output through exec

核能气质少年 提交于 2019-12-18 06:53:30
问题 Is there any way to apply bash variable substitution on find 's output? I know I've seen some one do it on stack overflow but I can't seem to find that particular post anymore. As an example , let's say I want to rename files *.png to *_copy.png . I know I can do this using rename but it's just a thought experiment. Now I'd like to be able to do something like this: find . -name "*png" -exec mv "{}" "${{}%.*}_copy.png" \; Which results in an invalid substitution . Of course, I could first

Substitutions inside links in reST / Sphinx

本秂侑毒 提交于 2019-12-17 22:43:34
问题 I am using Sphinx to document a webservice that will be deployed in different servers. The documentation is full of URL examples for the user to click and they should just work. My problem is that the host, port and deployment root will vary and the documentation will have to be re-generated for every deployment. I tried defining substitutions like this: |base_url|/path .. |base_url| replace:: http://localhost:8080 But the generated HTML is not what I want (doesn't include "/path" in the

sed error “Invalid range end”

依然范特西╮ 提交于 2019-12-17 19:49:54
问题 I run this substitution command on Ubuntu 12.04. $ sed -e "s/([a-zA-Z0-9.-/\\ :]+)/\1/g" However, the following error is raised. sed: -e expression #1, char 27: Invalid range end I can remember the same expression works on MacOSX. Can you describe why the command fails? 回答1: You can solve it in two ways. One of them is to use -r switch to avoid escaping special characters and move - in the range to first or last position and avoid its special meaning, it would be like: sed -re "s/([a-zA-Z0-9.