Questions tagged [string-substitution]

Substituting string excerpts via sed, awk and other utilities.

220 questions
2
votes
2 answers

ruby - how to pad "groups of 5 characters" with undersores in last group?

I want my string in groups of 5 characters, .e.g. thisisastring => ["thisi", "satri", "ng"] but I also want the last group to be padded with __'s, e.g. thisisastring => ["thisi", "satri", "ng___"] I have got as far as the string…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
2
votes
2 answers

Apache StringSubstitutor - Replace not matching variables with empty string

Precondition I have a string which looks like this: String myText= "This is a foo text containing ${firstParameter} and ${secondParameter}" And the code looks like this: Map textParameters=new…
MrNobody
  • 535
  • 8
  • 24
2
votes
5 answers

TSQL varchar string manipulation

I have a variable which contains the following string: AL,CA,TN,VA,NY I have no control over what I get in that variable (comes from reporting services) I need to make it look like this: 'AL','CA','TN','VA','NY' How do I do this?
Jeff
  • 8,020
  • 34
  • 99
  • 157
2
votes
2 answers

Perl, How to find and modify multiple expressions in a single string

I have a file that contains many lines like the following: some text { {{7.718 1072.463} {7.718 1230.985} {15.724 1230.985} {15.724 1198.742} {15.759 1198.742} } {{7.702 1072.489} {7.702 889.858} {13.418 889.858} {13.418 887.367} {13.435 887.367}…
daryl
  • 23
  • 2
2
votes
1 answer

StringSubstitutor not working with JSON text

I am trying to do some String Substitution using the StringSubstitutor . My payload is often JSOn and it doesnt replaces the token always. Example String ss = "{\"media\":[{\"channels2\":\"[Token2]\",\"channels\":\"[Token1]\"}]}"; final…
Aksanth
  • 269
  • 2
  • 13
2
votes
1 answer

How to substitute psql script variables into strings in the query so it doesn't fail regardless if the variable is set or not

What I want is for the same query not to fail - regardless of the variable being set or not. Then depending on the variable being set - returning relevant output. Here's more or less what I mean/want: --variable not set, returns not substituted…
2
votes
2 answers

How to use pg_trgm operators(e.g. %>) in django framework?

I'm using the pg_trgm for similarity search on PostgreSQL DB and I need to return the results to the front by using the Django model. But, I got a problem that the operator %> cannot be recognized by the Django framework. Any advice? Thank you. I…
2
votes
0 answers

Python - Replace text before first occurrence of string?

So if I have a string like: plz_work = "text I want to get rid of HELLO want to keep this text HELLO want to keep this text" I want to remove all the text before the first instance of HELLO, like the following: "HELLO want to keep this text HELLO…
ocean800
  • 3,489
  • 13
  • 41
  • 73
2
votes
2 answers

Extract text from inner-most nested parentheses of string

From the text string below, I am trying to extract a specific string subset. string <- c("(Intercept)", "scale(AspectCos_30)", "scale(CanCov_500)", "scale(DST50_30)", "scale(Ele_30)", "scale(NDVI_Tin_250)", "scale(Slope_500)", …
B. Davis
  • 3,391
  • 5
  • 42
  • 78
2
votes
1 answer

Restrict variable substitution in typesafe config

Using typesafe config it is both possible to perform variable substitution and outright overriding of both keys and values: config { substitution.required = ${VAR} should.not.override = "should not be overridden" } java -jar executable.jar…
murungu
  • 2,090
  • 4
  • 21
  • 45
2
votes
2 answers

cleaning a messy character column in R

I have a column as follows. Id Feedback 1 c("No", "No", "No", "No", "No", "No") 2 c("No", "No", "No") 3 c("No", "No", "No", "No", "Taking Medication") I am trying to get rid of the No such that the final results after…
2
votes
1 answer

Why does this sed command output "[18" instead of "18"?

echo [18%] | sed s:[\[%\]]::g I'm really confused by this, because the same exact pattern successfully replaces [18%] in vim. I've also tested the expression in a few online regex tools and they all say that it will match on the [, %, and ] as…
2
votes
3 answers

How do I write a method for multiple controllers that strips out an array of text?

I want to write a method that simplifies the names of corporations. I would like it to work as follows: @clear_company = clear_company(@company.name) What would happen is @company.name = "Company, Inc." @clear_company would be "Company" If…
Satchel
  • 16,414
  • 23
  • 106
  • 192
2
votes
1 answer

String substitution (${s//$foo/$bar}) in bash not working with backslashes

I have a string in variable and I would like to substitute it with another string, but the operation has no effect when the string being matched contains backslashes. This is the part of the script that doesn't…
willemdh
  • 796
  • 2
  • 13
  • 34
2
votes
4 answers

Conditionals on replacement in a string

So I may have a string 'Bank of China', or 'Embassy of China', and 'International China' I want to replace all country instances except when we have an 'of ' or 'of the ' Clearly this can be done by iterating through a list of countries, checking if…
redrubia
  • 2,256
  • 6
  • 33
  • 47
1 2
3
14 15