Questions tagged [string-substitution]

Substituting string excerpts via sed, awk and other utilities.

220 questions
0
votes
2 answers

Substitute multiple strings from a file over multiple files

Let's say I'm George Orwell and I want to replace all instances of "big" with "small", "rich" with "poor", "smart" with "stupid", etc across a bunch of files. So I create a text file with one line per substitution: file: substs.csv big, small rich,…
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
0
votes
2 answers

How to expand macros in strings read from a file in a ksh script?

I want to read a list of file names stored in a file, and the top level directory is a macro, since this is for a script that may be run in several environments. For example, there is a file file_list.txt holding the following fully qualified file…
yamex5
  • 195
  • 1
  • 11
0
votes
3 answers

Replace entire string by one specific word

I have this column in a df: Column1 very sunny day today it was sunny not very sunny today desired output Column1 sunny sunny not sunny df<-df%>% mutate(column_1=case_when( str_detect(column_1,"very sunny")~…
pipts
  • 87
  • 7
0
votes
1 answer

apache commons-text StringSubstitutor, valueMap.put("amount", 20.0); how to output `$20.0`?

code: Map valueMap = new HashMap<>(); valueMap.put("amount", 20.0); valueMap.put("id", 123456); StringSubstitutor ss = new StringSubstitutor(valueMap); // I expect output:…
Guo
  • 1,761
  • 2
  • 22
  • 45
0
votes
1 answer

Bad subsitution when trying to do string replacement with parameter expansion

Maybe this is a dumb question, but I'm writing a very small Gedit external tool for compiling .qrc (Qt resource files) on a key press. This is my code: echo $GEDIT_CURRENT_DOCUMENT_PATH pyrcc $GEDIT_CURRENT_DOCUMENT_PATH -o…
TheEagle
  • 5,808
  • 3
  • 11
  • 39
0
votes
1 answer

how to replace all substrings of a array of strings in bash?

I'm trying to list all files in a sub-directory without their path, I just want the file name and extension, but Bash substitution doesn't work with all paths in an array, it only works with the first element. Code: #!/usr/bin/bash NAME="$(pwd |…
0
votes
0 answers

Python regex replace alphanumeric with indent

I'm looking to leverage regex syntax to create an indent (new line) where certain criteria is met. In this case when there is an alphanumeric value following ), pattern. Something like this - but it is not quite working. text_old = some text some…
paranormaldist
  • 489
  • 5
  • 16
0
votes
1 answer

sed substitution is not working with variable

cat file.txt ...Some random string... ...String random string... service_account_file = $HOME/easyclone/accounts/1.json ...Some random string... ...Some random string... I just need to substitute the end part of line 3 ( 1 in this case , ie the…
Sachin
  • 1,217
  • 2
  • 11
  • 31
0
votes
1 answer

Using sed to convert IP address to company-standard DNS name?

I've got a COTS product that requires we set a certain configuration property with a DNS name, rather than an IP address. Fortunately, our company standardized what the DNS names for that class of servers will look like. For example, an IP of…
Shadowman
  • 11,150
  • 19
  • 100
  • 198
0
votes
1 answer

Combining multiple substitutions with regular expressions in python, django

Couldn't find any solution to my question from the questions answered before. I'd like to convert all words wrapped with symbols to respective texts by substituting them (in short, markdown to HTML). These are my patterns that match title, subtitle,…
Fayzulla
  • 89
  • 1
  • 8
0
votes
0 answers

Remove " " using gsub

I am using this code to remove HTML tags from the data as.data.frame(gsub("<[^>]+>", "", ReflectionData$Answer)) But this code does not remove the " ". The data is imported from Excel and the variable answer is a character that contains 12…
Arual
  • 12
  • 4
0
votes
1 answer

if an attribute is not present in map, How to replace the values in template string using strsubsitutor as null or empty string

I have a string String templateString = "The ${animal} jumps over the ${target}."; valuesMap.put("animal", "quick brown fox"); StrSubstitutor sub = new StrSubstitutor(valuesMap); String resolvedString = sub.replace(templateString); But there is no…
0
votes
2 answers

Why does my code remove 999 in my replacement code?

I have the code below to replace all punctuation with 999 and all alphabet characters with its number position. I have included the print statement that confirms punctuation is being replaced. However I seem to override with my remaining code to…
user10688328
0
votes
1 answer

Apache Log4j2 StrSubstitutor "default variable" does not work

I am trying to configure log4j2 logger. It uses Apache StringSubstitutor. I want to set default root directory as "${sys:catalina.home}/webapps/${contextName}/logs/". And if property "userRootpath" has been set in logger.properties file, app should…
Magentai
  • 33
  • 4
0
votes
1 answer

How to comment the whole line with Vim substitute() and &commentstring

I've been trying to write a vimscript that reads the output of a shell command (figlet) and comments every line of it. I want to use the &commentstring variable since I want this script to work with any filetype. So far I have achieved only…
user13462564