Questions tagged [string-substitution]

Substituting string excerpts via sed, awk and other utilities.

220 questions
1
vote
2 answers

How to delete string or digits after certain pattern?

If there is a vector x that is, x <- c('/name12/?ad_2','/name13/?ad_3','/name14/?ad_4') Is there a way to delete the following numbers after 'ad_'? so the converted x appears as '/name12/?ad_' '/name13/?ad_' '/name14/?ad_' I was trying to use…
TrebiLime
  • 35
  • 5
1
vote
1 answer

Replace specific named group with re.sub in python

I create a regular expression to find urls like /places/:state/:city/whatever p = re.compile('^/places/(?P[^/]+)/(?P[^/]+).*$') This works just fine: import re p = re.compile('^/places/(?P[^/]+)/(?P[^/]+).*$') path =…
Rob Crowell
  • 1,447
  • 3
  • 15
  • 25
1
vote
1 answer

Why is the variable's value not substituted in the string?

Hai, can anyone help me... When I write like: $file=file_get_contents('https://graph.facebook.com/me?access_token=1932993|twetrg|vsfgsewr'); the code gets response as well good. but when I write like: 1. $tk=''; 2.…
JAMES
  • 11
  • 1
1
vote
1 answer

Strip off characters from xargs {} in bash

Assume I have files named "*.data.done". Now I want to rename them (recursively) back to "*.data" then ones which contains "pattern" So here we go: grep -l -R -F "pattern" --include '*.data.done' * | xargs -I{} mv {} ${{}::-5} Well, this stripping…
robert
  • 1,921
  • 2
  • 17
  • 27
1
vote
1 answer

Regex :: Complex Substitutions

I am trying to "prettify" a certain type of number object in my solution. This particular type has the following possible representations, along with their pretty representations: xxxxxyyyyyyy => xxxxx-yyyyyyy xxxxxyyyyyyyz =>…
AweSIM
  • 1,651
  • 4
  • 18
  • 37
1
vote
2 answers

convert git diff of sql schema file to apply/undo sql scripts

I'm trying to make a simple bashscript, that given an output from git diff of a sql schema definition file, would be able to create an update script and undo script. So having an input like this: create table xxx ( - aaa numeric(18) primary…
murison
  • 3,640
  • 2
  • 23
  • 36
1
vote
1 answer

Bash one-liner to replace all [:punct:] characters with those same characters escaped

my current kind of unsolved problem with bash is how to replace all the characters in the [:punct:] class, that is [!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~] , each with the same character escaped by a backslash. For example, I want ^h?e.l*l+o: to…
the_eraser
  • 381
  • 1
  • 3
  • 14
1
vote
3 answers

string substitution in python - unsupported operand type(s) for %: 'list' and 'str'

I'm stuck with a simple piece of code, I'm sure it's just a silly mistake, I hope someone can point it out to me. Here the code I have: a = ['_a','_b','_c'] data_template = ['data%s'] for f in a: this_data = data_template % (f) print…
Alex
  • 516
  • 5
  • 12
1
vote
1 answer

Multi-character substitution cipher algorithm

My problem is the following. I have a list of substitutions, including one substitution for each letter of the alphabet, but also some substitutions for groups of more than one letter. For example, in my cipher p becomes b, l becomes w, e becomes i,…
1
vote
1 answer

edit variable value in a batch file using another batch

existing A.bat : rem set variable pathVariable to appropriate value set pathVariable=../Doc/English/MyDoc.htm rem asd from B.bat, I need to update the value of pathVariable with a path containing spaces, but after replacing spaces with %20 So…
1
vote
1 answer

strange execution of re.sub() in python

Consider the following execution. Python 2.7.2 (default, Sep 19 2012, 01:44:39) [GCC 4.2.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> old_value=1 >>> new_value=2 >>>…
bbv
  • 501
  • 1
  • 5
  • 14
1
vote
2 answers

Find-and-replace perl regex including math

I'm working on a project and, due to a simple but very unfortunate mistake, need to rewrite a bunch of timestamps in a file; specifically, I need to take the final part of each timestamp and divide it by 30. For example, if the file contains:…
spiffl
  • 23
  • 7
1
vote
2 answers

Changing numbers within string in R?

I have a problem where I would appreciate any ideas on how to do it with R. The problem is this: I have a latex-table stored. The numbers in the table are all equipped with three digits after the decimal point. I want to cut these digits off,…
coffeinjunky
  • 11,254
  • 39
  • 57
1
vote
2 answers

Python Regular Expression: Replace Withing a group

Is there a way to do substitution on a group? Say I am trying to insert a link into text, based on custom formatting. So, given something like this: This is a random text. This should be a [[link somewhere]]. And some more text at the end. I want…
Goro
  • 9,919
  • 22
  • 74
  • 108
1
vote
3 answers

How do I substitute special characters with escaped version in a Bash script

I swear I have looked and looked and looked. If I've missed the answer to this somewhere, I apologize; it means my search-fu failed me, not that I haven't tried. I'm relatively new to bash scripts (:sigh: newbie), but I'm trying to write one that…
Wilson F
  • 1,250
  • 1
  • 20
  • 37