Questions tagged [string-substitution]

Substituting string excerpts via sed, awk and other utilities.

220 questions
0
votes
1 answer

Confused by a combination of globbing, variable substitution and find command in bash

I am trying to pass a quoted globbing pattern to find command in script using variable. Does not work without eval. Is it a way to do this without eval? First I use the followin command: find . -name '*a*' It works OK and produces the following…
0
votes
2 answers

How to censor ONLY swear words with gsub

I've got a text corpus containing some swear words and I tried to censor them, but upon further inspection I realised that the regular expression I used doesn't quite fit yet and also proper words get censored due to that. x <- c("ass", "badass",…
ZaLa
  • 3
  • 1
0
votes
2 answers

Declare a here-string containing variables outside of a loop

I would like to declare a here-string outside of a loop use that string in the loop where the variables get resolved. My ideal scenario would look like below. This doesn't work as Powershell evaluates the string one time before entering the loop…
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
0
votes
1 answer

Replacing column names in list of data.frames by finding pattern R

I have list of many data.frames with similar column names, which I would like to standardise by finding a pattern and replacing the whole string character. I have the following function, but for some reason it doesn't work as I would like it…
MIH
  • 1,083
  • 3
  • 14
  • 26
0
votes
2 answers

How to replace \r\n characters in a text string specifically in R

For the life of me, I am unable to strip out some escape characters from a text string (prior to further processing). I've tried stringi, gsub, but I just cannot get the correct syntax. Here is my text string txt <- "c(\"\\r\\n Stuff from a…
Jon
  • 445
  • 3
  • 15
0
votes
0 answers

Makefile string substitution using variable

I want to remove the root directory of a targeted path in a Makefile. Let say the target is like OUTPUT = output PATH = $(OUTPUT)/a.txt Later when building the target, this works echo $(@:output/%=%) >>> a.txt But not if I use the var $OUTPUT…
user3240484
  • 209
  • 1
  • 4
0
votes
1 answer

How could I remove a vector of strings from a column of strings in R?

I have a column of company names. db_name$name I've found the 100 most common endings (Inc, Ltd, GmbH, Co, etc.), and concatenated them to make them easier to use with Regular Expressions. `db_name$ending <- word(db_name$name,-1) db_end_count <-…
0
votes
0 answers

R: remove characters before a specific string

I am trying to remove characters from specific words from twitter text mining, lamentably my text has wrong word and ending because of accent: my result: “una murià result expected: una murio I am using gsub : mach_text = gsub("una$,"",…
Rodrigo B
  • 21
  • 7
0
votes
1 answer

Removing commas from strings and numbers

Using R, how do I remove commas if its a number and replace commas with a space if its a letter?: Company | Sales | ------------------------- go, go, llc |2,550.40 | tires & more | 500 | l-m tech |1,000.67…
user4852067
0
votes
1 answer

awk display variable with environment content

I'm getting from system one variable that returns a string, like: $VARIABLE/dir/text.file I tryed to use gsub, but I'm missing something: onstat -c | grep ^MSGPATH | awk 'gsub (/$INFORMIXDIR/, ${INFORMIXDIR}) {print $2}' It returns error: awk:…
0
votes
1 answer

How to replace every occurance of multiple strings in a column with one unique new string in R

I have a column in a dataset which starts with M, F or I. I want to replace all the M or F in the column with MF and leave I untouched. data$Sex: "M" "F" "I" "F" "M" "I" I have tried the snippet as shown below, but to no avail.: df <-…
Dkk
  • 73
  • 2
  • 9
0
votes
2 answers

R remove string before delimiter

I have one of the column in the dataframe and I would like to remove part of the string before the 5th delimiter "." and the last "." for .txt and I don't know how to do…
Peter Chung
  • 1,010
  • 1
  • 13
  • 31
0
votes
2 answers

Surrounding one group with special characters in using substitute in vim

Given string: some_function(inputId = "select_something"), (...) some_other_function(inputId = "some_other_label") I would like to arrive at: some_function(inputId = ns("select_something")), (...) some_other_function(inputId =…
Konrad
  • 17,740
  • 16
  • 106
  • 167
0
votes
1 answer

Writing a user-defined function that accepts an oldstring, searches a dataframe column, and replaces with a newstring

I have a dataset blah with a column kw. There are tens of thousands of strings, some of which are sentence-length. I already replaced the vast majority of what I want to replace with a for loop, replacing substrings with substring categories.…
mowshowitz
  • 69
  • 6
0
votes
2 answers

using gsub function in r to remove slash

suppose I have a string that has the following characters "\"------------080209060700030309080805\"" And now I want to use gsub function in r to remove the "\ and \" part, and only keep the following…
tql66
  • 11
  • 1
  • 2