bash : Bad Substitution

The default shell (/bin/sh) under Ubuntu points to dash, not bash. me@pc:~$ readlink -f $(which sh) /bin/dash So if you chmod +x your_script_file.sh and then run it with ./your_script_file.sh, or if you run it with bash your_script_file.sh, it should work fine. Running it with sh your_script_file.sh will not work because the hashbang line will be … Read more

How do I create a “macro” for regressors in R?

Here are some alternatives. No packages are used in the first 3. 1) reformulate fo <- reformulate(regressors, response = “income”) lm(fo, Duncan) or you may wish to write the last line as this so that the formula that is shown in the output looks nicer: do.call(“lm”, list(fo, quote(Duncan))) in which case the Call: line of … Read more

JavaScript – Replace all commas in a string [duplicate]

The third parameter of String.prototype.replace() function was never defined as a standard, so most browsers simply do not implement it. The best way is to use regular expression with g (global) flag. var myStr=”this,is,a,test”; var newStr = myStr.replace(/,/g, ‘-‘); console.log( newStr ); // “this-is-a-test” Still have issues? It is important to note, that regular expressions … Read more

How can I use a variable in the replacement side of the Perl substitution operator?

On the replacement side, you must use $1, not \1. And you can only do what you want by making replace an evalable expression that gives the result you want and telling s/// to eval it with the /ee modifier like so: $find=”start (.*) end”; $replace=””foo $1 bar””; $var = “start middle end”; $var =~ … Read more

Command substitution: backticks or dollar sign / paren enclosed? [duplicate]

There are several questions/issues here, so I’ll repeat each section of the poster’s text, block-quoted, and followed by my response. What’s the preferred syntax, and why? Or are they pretty much interchangeable? I would say that the $(some_command) form is preferred over the `some_command` form. The second form, using a pair of backquotes (the “`” … Read more

Can’t use ‘\1’ backreference to capture-group in a function call in re.sub() repr expression

The reason the re.sub(r'([0-9])’,A[int(r’\g<1>’)],S) does not work is that \g<1> (which is an unambiguous representation of the first backreference otherwise written as \1) backreference only works when used in the string replacement pattern. If you pass it to another method, it will “see” just \g<1> literal string, since the re module won’t have any chance … Read more

Python Regex escape operator \ in substitutions & raw strings

First and foremost, replacement patterns ≠ regular expression patterns We use a regex pattern to search for matches, we use replacement patterns to replace matches found with regex. NOTE: The only special character in a substitution pattern is a backslash, \. Only the backslash must be doubled. Replacement pattern syntax in Python The re.sub docs … Read more

tech