substitution

cygwin sed substitution against commands in history

I couldn't find an answer for this exact problem, so I'll ask it. I'm working in Cygwin and want to reference previous commands using !n notation, e.g., if command 5 was which ls, then !5 runs the same command. The problem is when trying to do substitution, so running: !5:s/which \([a-z]\)/\1/ should just run ls, or whatever the arg...

Substitute the n-th occurrence of a word in vim

I saw other questions dealing with the finding the n-th occurrence of a word/pattern, but I couldn't find how you would actually substitute the n-th occurrence of a pattern in vim. There's the obvious way of hard coding all the occurrences like :s/.*\(word\).*\(word\).*\(word\).*/.*\1.*\2.*newWord.*/g Is there a better way of doing ...

Non-sequential substitution in SymPy

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 substi...

How many substitutions took place in a Perl s///g?

Well, the title says it all. Small example: perl -e '$s="aaabbcc";$c=()=$s=~/a/g;print"$c\n$s\n"' (m//g) outputs 3 aaabbcc whereas perl -e '$s="aaabbcc";$c=()=$s=~s/a/x/g;print"$c\n$s\n"' (s///g) outputs 1 xxxbbcc I'd like to do both things at once without having to match first: substitute and know the number of substitutions. Obv...

How to use ASP.Net server controls inside of Substitution control ?

while the method we use in Substitution control should return strings, so how is it possible to use a donut caching in web forms on a server control which should be rendered server side? for example Loginview control? ...

string or list substitution in Python

hi all... how would I go about taking a string ("h1", "h2", "h3, "h4") And substituting these values with numbers 1, 2, 3, 4? Correspondingly, how I would I preform the same operation but on a list instead? Thanks in advance... ...

ListId GUID substitution in CAML in Share Point 2010 (and other subsitutions)

There's a new syntax element in SP 2010's feature definitions {$ListId:Lists/ListName}. Apparently it should replace it with the GUID of the list on traget site. This solves a problem where you don't know the GUID before you create the list and have to use a feature receiver to define elements which need the GUID. Is there other such su...

How to use a variable as modifier in a substitution

Is there a way to use a variable as modifier in a substitution? my $search = 'looking'; my $replace = '"find: $1 ="'; my $modifier = 'ee'; s/$search/$replace/$modifier; I need to use an array of hashes to make bulk search-replace with different modifiers. ...

Perl: using variable in substitution

Possible Duplicate: How to use a variable in the replacement side of the Perl substitution operator? I would like to do something like $sub = "\\1"; $match = "hi(.*)"; $str = "hi1234" $res = $str; $res =~ s/$match/$sub/g I would like this to return 1234 but in this case it returns \1. I.e. I want it to be equivalent to s/$m...

How do I use variables to do substitution in Perl?

I have several text files, that were once tables in a database, which is now disassembled. I'm trying to reassemble them, which will be easy, once I get them into a usable form. The first file, "keys.text" is just a list of labels, inconsistently formatted. Like: Sa 1 # Sa 2 U 328 #* It's always letter(s), [space], number(s), [spac...

Inline regex replacement in perl

Is there a way to replace text with a regex inline, rather than taking the text from a variable and storing it in a variable? I'm a perl beginner. I often find myself writing my $foo = $bar; $foo =~ s/regex/replacement/; doStuff($foo) where I'd really like to write doStuff($bar->replace(s/regex/replacement/)); or the like, rather...

Perl: Global substitution within tag-delimited string

My goal is to replace all instances of a trailing - to a trailing + within tag brackets. Lets assume the line to be replaced looks like this: <h> aa- aa- </h> <h> ba- ba- </h> and should afterwards look like <h> aa+ aa+ </h> <h> ba+ ba+ </h> First I tried this expression: s/<h>(.*?)-(.*?)<\/h>/<h>$1+$2<\/h>/g; which yielded th...

Perl: Global substition within tag delimited string

My previous post got the tags partially stripped, so here it is again: My goal is to replace all instances of a trailing - to a trailing + within tag brackets. Lets assume the line to be replaced looks like this: <h> aa- aa- </h> <h> ba- ba- </h> and should afterwards look like <h> aa+ aa+ </h> <h> ba+ ba+ </h>. First I tried th...

how to substitute part of a string in python?

How to replace a set of characters inside another string in Python? Here is what I'm trying to do: let's say I have a string 'abcdefghijkl' and want to replace the 2-d from the end symbol (k) with A. I'm getting an error: >>> aa = 'abcdefghijkl' >>> print aa[-2] k >>> aa[-2]='A' Traceback (most recent call last): File "<pyshell#2>",...

JavaScript: Can you substitute variables into anonymous functions on creation?

Possible Duplicate: Javascript closure inside loops - simple practical example Rather than explaining the question, I'll give an example: for (var i = 0; i < 100; i ++) { get_node(i).onclick = function() { do_something_very_important(i); } } Is there any way to have the value of i substituted into the function upon ...

Substitute output from variable to give another output.

I am trying to substitute output from variable to give another output. The variable i have problems with is the $apps. It gives me "syntax error: bad substitution". $appletDir is a directory with desktop shortcuts. The problem is that some shortcuts do not have the same name as the icon(png). So i need to substitute the program name wi...

Maven: property substitution not done for /project/version tag of pom?

http://maven.apache.org/pom.html#Properties says property "values are accessible anywhere within a POM". Should this read "are accessible in most places within a POM"? I can specify the version of a dependency no problem like so: <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}...

SED substitution for variable

I have a file named check.txt which has the below contents: $ cat check.txt ~/bin/tibemsadmin -server $URL-user $USER -password $PASWRD $ I have a main script where the values of $URL, $USER, $PASWRD are obtained from the main script. I want to use the SED utility to replace the $URL, $USER, $PASWRD to the actual values in the check....

Very basic replace using sed

Really would appreciate help on this. I am using sed to create a CSV file. Essentially multiple html files are all merged to a single html file and sed is then used to remove all the junk pictures etc to get to the raw columnar data. I have all this working but am stuck on the last bit. What I want to do is very basic - I want to repl...

PHP: foreach variable assignment and referencing: how-to?

I have an array: $aPerfparse as 2-dimensional array where index ranges from 0 to n-1, * aPerfparse[index]['label'] - label of the perfdata * ['value'] - actual perfdata * ['uom'] - unit of measurement (might be NULL) Need to iterate through each item and set each ...