substitution

sed substitute whitespace for dash only between specific character patterns

笑着哭i 提交于 2020-01-04 05:27:10
问题 I have a lines like these: ORIGINAL sometext1 sometext2 word:A12 B34 C56 sometext3 sometext4 sometext5 sometext6 word:A123 B45 C67 sometext7 sometext8 sometext9 sometext10 anotherword:(someword1 someword2 someword3) sometext11 sometext12 EDITED asdjfkklj lkdsjfic kdiw:A12 B34 C56 lksjdfioe sldkjflkjd lknal niewoc kdiw:A123 B45 C678 oknes lkwid cnqule nkdal anotherword:(kdlklks inlqok mncvmnx) unqieo lksdnf Desired output: asdjfkklj lkdsjfic kdiw:A12-B34-C56 lksjdfioe sldkjflkjd lknal niewoc

Using Bash/Perl to modify files based on each file's name

冷暖自知 提交于 2020-01-04 03:57:15
问题 I have a few hundred files which all contain variations of the same class, 'Process'. My intention is to make each class a derived class of some base clase 'BaseProcess'. Every file has been manually renames to something like 'Process_XXX' and I am trying to find a way of going through every file and changing every occurrence of, for example: class Process { stuff; } to class Process_XXX : public BaseProcess { stuff; } where XXX is taken from the particular file being changed. Is this

SymPy, simplification / substitution using known patterns or sub-expressions

与世无争的帅哥 提交于 2020-01-03 08:43:07
问题 I have the following expression: from sympy import pi, sin, cos, var, simplify var('j,u,v,w,vt,wt,a2,t,phi') u0 = v*a2*sin(pi*j/2 + pi*j*t*phi**(-1)/2) + pi*vt*a2*cos(pi*j/2 + pi*j*t*phi**(-1)/2)*j*phi**(-1)/2 + pi*w*a2*cos(pi*j/2 + pi*j*t*phi**(-1)/2)*j*phi**(-1) Which can be simplified: print simplify(u0) #a2*(pi*j*vt*cos(pi*j*(phi + t)/(2*phi)) + 2*pi*j*w*cos(pi*j*(phi + t)/(2*phi)) + 2*phi*v*sin(pi*j*(phi + t)/(2*phi)))/(2*phi) Given the sub-expressions: bj = pi*j*(phi + t)/(2*phi) cj = j

Getting the parse tree for a predefined function in R

旧时模样 提交于 2020-01-01 05:56:09
问题 I feel as if this is a fairly basic question, but I can't figure it out. If I define a function in R, how do I later use the name of the function to get its parse tree. I can't just use substitute as that will just return the parse tree of its argument, in this case just the function name. For example, > f <- function(x){ x^2 } > substitute(f) f How should I access the parse tree of the function using its name? For example, how would I get the value of substitute(function(x){ x^2 }) without

Padding multiple character with space - python

三世轮回 提交于 2019-12-31 04:22:48
问题 In perl , I can do the following with will pad my punctuation symbols with spaces: s/([،;؛¿!"\])}»›”؟%٪°±©®।॥…])/ $1 /g;` In Python , I've tried this: >>> p = u'،;؛¿!"\])}»›”؟%٪°±©®।॥…' >>> text = u"this, is a sentence with weird» symbols… appearing everywhere¿" >>> for i in p: ... text = text.replace(i, ' '+i+' ') ... >>> text u'this, is a sentence with weird \xbb symbols \u2026 appearing everywhere \xbf ' >>> print text this, is a sentence with weird » symbols … appearing everywhere ¿ But

Using paste and substitute in combination with quotation marks in R

限于喜欢 提交于 2019-12-31 04:18:06
问题 Please note that I already had a look at this and that but still cannot solve my problem. Suppose a minimal working example: a <- c(1,2,3) b <- c(2,3,4) c <- c(4,5,6) dftest <- data.frame(a,b,c) foo <- function(x, y, data = data) { data[, c("x","y")] } foo(a, b, data = dftest) Here, the last line obviously returns an Error: undefined columns selected . This error is returned because the columns to be selected are x and y , which are not part of the data frame dftest . Question: How do I need

Removing consecutive duplicates words out of text using Regex and displaying the new text

梦想的初衷 提交于 2019-12-30 07:03:34
问题 Hy, I have the following code: import java.io.*; import java.util.ArrayList; import java.util.Scanner; import java.util.regex.*; / public class RegexSimple4 { public static void main(String[] args) { try { Scanner myfis = new Scanner(new File("D:\\myfis32.txt")); ArrayList <String> foundaz = new ArrayList<String>(); ArrayList <String> noduplicates = new ArrayList<String>(); while(myfis.hasNext()) { String line = myfis.nextLine(); String delim = " "; String [] words = line.split(delim); for

Substitute the n-th occurrence of a word in vim

╄→гoц情女王★ 提交于 2019-12-30 00:37:09
问题 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 this? 回答1: You can do this a little more simply by using multiple searches. The empty pattern in the :s/pattern/repl/ command means replace the most recent search

Replacing ^ and | sybmbols in a matrix

Deadly 提交于 2019-12-29 09:36:08
问题 I have the following table: column1 column2 1 aaa^bbb 2 aaa^bbb|ccc^ddd I would like to have a output file as follows: column1 column2 column3 1 aaa bbb 2 aaa bbb 3 ccc ddd Could you mind to let me know if there are smart way of doing this? Update: I was trying to do two things; For ^, I want to separate the context to the column 2 and column 3. For |, I want to separate it to the next row, but keeping the same number in column1 (the column1 is the same for row 2 and 3. Sorry that I make a

All possible combinations of selected character substitution in a string in ruby

可紊 提交于 2019-12-29 07:14:30
问题 I was wondering if there is a simple way to do every combination of selected character substitutions in ruby in a simple way. An example: string = "this is a test" subs = ['a'=>'@','i'=>'!','s'=>'$'] subs.combination.each { |c| string.gsub c } would yield "this is @ test" "th!s !s a test" "thi$ i$ a te$t" "th!s !s @ test" "thi$ i$ @ te$t" "th!$ !$ a te$t" "th!$ !$ @ te$t" Thanks for the help! 回答1: string = "this is a test" subs = ['a'=>'@','i'=>'!','s'=>'$'] subs = subs.first.map(&:to_a) 1