substitution

Bad substitution error in ksh [duplicate]

廉价感情. 提交于 2020-01-15 09:13:22
问题 This question already has answers here : Cannot debug simple ksh programme (2 answers) Closed 5 years ago . The following KornShell (ksh) script should check if the string is a palindrome. I am using ksh88 , not ksh93 . #!/bin/ksh strtochk="naman" ispalindrome="true" len=${#strtochk} i=0 j=$((${#strtochk} - 1)) halflen=$len/2 print $halflen while ((i < $halflen)) do if [[ ${strtochk:i:1} == ${strtochk:j:1} ]];then (i++) (j--) else ispalindrome="false" break fi done print ispalindrome But I am

Bad substitution error in ksh [duplicate]

为君一笑 提交于 2020-01-15 09:12:32
问题 This question already has answers here : Cannot debug simple ksh programme (2 answers) Closed 5 years ago . The following KornShell (ksh) script should check if the string is a palindrome. I am using ksh88 , not ksh93 . #!/bin/ksh strtochk="naman" ispalindrome="true" len=${#strtochk} i=0 j=$((${#strtochk} - 1)) halflen=$len/2 print $halflen while ((i < $halflen)) do if [[ ${strtochk:i:1} == ${strtochk:j:1} ]];then (i++) (j--) else ispalindrome="false" break fi done print ispalindrome But I am

Suppress C Macro Variable Substitution

允我心安 提交于 2020-01-14 08:04:31
问题 I have this bit of code (part of an interpreter for a garbage-collected Forth system, actually): #define PRIMITIVE(name) \ do \ { \ VocabEntry* entry = (VocabEntry*)gc_alloc(sizeof(VocabEntry)); \ entry->code = name; \ entry->name = cstr_to_pstr(#name); \ entry->prev = latest_vocab_entry; \ latest_vocab_entry = entry; \ } \ while (false) PRIMITIVE(dup); PRIMITIVE(drop); PRIMITIVE(swap); // and a lot more but there's a problem: in the line entry->name = cstr_to_pstr(#name); the name field is

Suppress C Macro Variable Substitution

帅比萌擦擦* 提交于 2020-01-14 08:03:14
问题 I have this bit of code (part of an interpreter for a garbage-collected Forth system, actually): #define PRIMITIVE(name) \ do \ { \ VocabEntry* entry = (VocabEntry*)gc_alloc(sizeof(VocabEntry)); \ entry->code = name; \ entry->name = cstr_to_pstr(#name); \ entry->prev = latest_vocab_entry; \ latest_vocab_entry = entry; \ } \ while (false) PRIMITIVE(dup); PRIMITIVE(drop); PRIMITIVE(swap); // and a lot more but there's a problem: in the line entry->name = cstr_to_pstr(#name); the name field is

Vim - Performing substitution on certain lines only

好久不见. 提交于 2020-01-14 06:22:13
问题 I have found the following in my quest to perform a substitution on even numbered lines only: :g/^/if !(line('.')%2)|s/foo/bar/g|endif Works great. But can someone please explain the need for the | characters in the command section of the :g call? 回答1: The | character is the command separator ; with it, you can concatenate multiple Ex commands in a single line, without adding newlines. See :help :bar. So, your conditional is equivalent to the following: if !(line('.')%2) s/foo/bar/g endif

Perl hash substitution with special characters in keys

只谈情不闲聊 提交于 2020-01-11 14:47:28
问题 My current script will take an expression, ex: my $expression = '( a || b || c )'; and go through each boolean combination of inputs using sub/replace, like so: my $keys = join '|', keys %stimhash; $expression =~ s/($keys)\b/$stimhash{$1}/g; So for example expression may hold, ( 0 || 1 || 0 ) This works great. However, I would like to allow the variables (also in %stimhash) to contain a tag, *. my $expression = '( a* || b* || c* )'; Also, printing the keys of the stimhash returns: a*|b*|c* It

Perl hash substitution with special characters in keys

可紊 提交于 2020-01-11 14:47:12
问题 My current script will take an expression, ex: my $expression = '( a || b || c )'; and go through each boolean combination of inputs using sub/replace, like so: my $keys = join '|', keys %stimhash; $expression =~ s/($keys)\b/$stimhash{$1}/g; So for example expression may hold, ( 0 || 1 || 0 ) This works great. However, I would like to allow the variables (also in %stimhash) to contain a tag, *. my $expression = '( a* || b* || c* )'; Also, printing the keys of the stimhash returns: a*|b*|c* It

How to substitute a special character between words in R [duplicate]

ⅰ亾dé卋堺 提交于 2020-01-10 05:28:44
问题 This question already has answers here : How to replace many special characters with “something plus special characters” in R (3 answers) Closed 4 years ago . I have a string of characters. str = c(".wow", "if.", "not.confident", "wonder", "have.difficulty", "shower") I am trying to replace "." in between words with a whitespace. So it would look like this ".wow", "if.", "not confident", "wonder", "have difficulty", "shower" First, I tried gsub("[\\w.\\w]", " ", str) [1] " o " "if" "not

Substitution versus (OPE-based) renaming

做~自己de王妃 提交于 2020-01-06 19:55:13
问题 Based on this suggestion I am trying to use order-preserving embeddings to represent renamings in a project where I am going to need two levels of contexts (types live in a kinding context of type variable kinds, and terms live in a typing context of term variable types). In my full code, I have substitution for types fully implemented; but a single hole remains in the function that does type-renaming of terms (so this is for renaming type variables). Below is my attempt at recreating the

awk - remove character in regex

回眸只為那壹抹淺笑 提交于 2020-01-05 21:31:10
问题 I want to remove 1 with awk from this regex: ^1[0-9]{10}$ if said regex is found in any field. I've been trying to make it work with sub or substr for a few hours now, I am unable to find the correct logic for this. I already have the solution for sed: s/^1\([0-9]\{10\}\)$/\1/ , I need to make this work with awk . Edit for input and output example. Input: 10987654321 2310987654321 1098765432123 (awk twisted and overcomplicated syntax) Output: 0987654321 2310987654321 1098765432123 Basically