substitution

Variable Substitution in C

寵の児 提交于 2019-12-11 10:24:22
问题 I want to open a file. Easy enough. Use fopen(). However, what file to open depends on the user input. I am somewhat proficient in Korn Shell scripting and this is easily done using variable substitution: $(var). I am unable to figure out the correct format in C. Could someone please give me some insight? My code - #include <stdlib.h> #include <stdio.h> char statsA[100]; char fileA[50]; int main (void) { printf("Enter file to open\n"); gets(fileA); FILE *statsA; statsA = fopen("c:/Users/SeanA

How can I consolidate several Perl one-liners into a single script?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 09:14:11
问题 I would like to move several one liners into a single script. For example: perl -i.bak -pE "s/String_ABC/String_XYZ/g" Cities.Txt perl -i.bak -pE "s/Manhattan/New_England/g" Cities.Txt Above works well for me but at the expense of two disk I/O operations. I would like to move the aforementioned logic into a single script so that all substitutions are effectuated with the file opened and edited only once. EDIT1: Based on your recommendations, I wrote this snippet in a script which when invoked

Substitute in vim, with special characters

走远了吗. 提交于 2019-12-11 08:50:39
问题 I am trying to use substitute command in vim to enclose all occurences of a particular pattern \cite{author1} \cite{author2} with (\cite{author1}) (\cite{author2}) Based on other answers in stack exchangeI used the following vim command %s/\\cite{(\w\+)}/(\\cite{\1})/g But, no luck. It says "no matches found". I put two back slashes, one of which is supposed to be the escape character. Kindly help. I know I could use some other editor and finish the job, but I want to know my mistake. Thank

Bash parameter substitution

好久不见. 提交于 2019-12-11 07:39:10
问题 I am trying to learn bash parameter substitution and have a very basic question: Why does this work: #!/bin/sh v1="-E" v2="s/./x/g" sed "$v1" "$v2" <<<"abc" # result = "xxx" but this doesn't work: #!/bin/sh v1="-E" v2="s/./x/g" sed "$v1 $v2" <<<"abc" # result = "sed: illegal option..." I am using Mac OS X bash. 回答1: Because on the second example, (the wrong one) you are using the quotes wrong. The quotes are being used in order to specify that what whatever comes out of that variable has to

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

巧了我就是萌 提交于 2019-12-11 06:00:41
问题 I have a string S = '02143' and a list A = ['a','b','c','d','e'] . I want to replace all those digits in 'S' with their corresponding element in list A . For example, replace 0 with A[0] , 2 with A[2] and so on. Final output should be S = 'acbed' . I tried: S = re.sub(r'([0-9])', A[int(r'\g<1>')], S) However this gives an error ValueError: invalid literal for int() with base 10: '\\g<1>' . I guess it is considering backreference '\g<1>' as a string. How can I solve this especially using re

how to strip the beginning of a file with python library re.sub?

谁都会走 提交于 2019-12-11 04:51:55
问题 I'm happy to ask my first python question !!! I would like to strip the beginning (the part before the first occurrence of the article) of the sample file below. To do this I use re.sub library. below this is my file sample.txt: fdasfdadfa adfadfasdf afdafdsfas adfadfadf adfadsf afdaf article: name of the first article aaaaaaa aaaaaaa aaaaaaa article: name of the first article bbbbbbb bbbbbbb bbbbbbb article: name of the first article ccccccc ccccccc ccccccc And my Python code to parse this

VIM: Delete pattern IF submatch(1) is empty

百般思念 提交于 2019-12-11 04:15:18
问题 This command line parses a contact list document that may or may not have either a phone, email or web listed. If it has all three then everything works great - appending the return from the FormatContact() at the end of the line for data uploading: silent!/^\d/+1|ki|/\n^\d\|\%$/-1|kj|'i,'jd|let @a = substitute(@",'\s*Phone: \([^,]*\)\_.*','\1',"")|let @b = substitute(@",'^\_.*E-mail:\s\[\d*\]\([-_@.0-9a-zA-Z]*\)\_.*','\1',"")|let @c = substitute(@",'^\_.*Web site:\s*\[\d*\]\([-_.:/0-9a-zA-Z]

Single sed command for multiple substitutions?

女生的网名这么多〃 提交于 2019-12-11 04:09:26
问题 I use sed to substitute text in files. I want to give sed a file which contains all the strings to be searched and replaced in a given file. It goes over .h and .cpp files. In each file it searches for file names which are included in it. If found, it substitutes for example "a.h" with "<a.h>" (without the quotes). The script is this: For /F %%y in (all.txt) do for /F %%x in (allFilesWithH.txt) do sed -i s/\"%%x\"/"\<"%%x"\>"/ %%y all.txt - List of files to do the substitution in them

Python Regular Expression: why does this not work?

这一生的挚爱 提交于 2019-12-11 04:02:00
问题 This does not give me an error nor an answer. re.sub('\\.(\\W|\\.)*[o0](\\W|[o0])*', '*', '..........................................') Why does it behave like so? Also, if I reduce the amount of 'periods', then it works. Thank you. 回答1: You've got catastrophic backtracking. 回答2: You have no o or 0 in your input string, yet your regular expression requires at least one of those characters to be there ( [o0] ). >>> re.compile('\\.(\\W|\\.)*[o0](\\W|[o0])*', re.DEBUG) literal 46 max_repeat 0

sed - delete only words with vowels

﹥>﹥吖頭↗ 提交于 2019-12-11 02:55:03
问题 I am trying to delete all words that start with a vowel as per below. The sed command I have is only deleting the first word if it has a vowel, not any others. I thought the boundary marker below and using the g would capture all words but it is not doing it. How do I get it to get all words with vowels ? echo "Always take a Big Apple " | sed -r 's/\b^[AEIOUaeiou]\w*//g' 回答1: Remove ^ sed -r 's/\b[AEIOUaeiou]\w*//g' you don't need to anchor it to the beginning of line, enough that you request