Questions tagged [string-substitution]

Substituting string excerpts via sed, awk and other utilities.

220 questions
1
vote
1 answer

Python mysql string substitution not working

I've been using this syntax with great success in python mysql. search = "O'%" # find names like O'Brien or O'Connell... cursor.execute (""" select userid from usertab where name like %s """ , (search)) But sometimes I need to build…
panofish
  • 7,578
  • 13
  • 55
  • 96
1
vote
1 answer

How to redirect to another handler in web.py from a POST method

The project is a simple web crawler and and search engine. The "Index" handler has a form for entering the domain to search and the term to find. I would like the POST method to redirect to the "LuckySearch" handler, which searches for the regex…
Dan
  • 147
  • 2
  • 8
1
vote
4 answers

managing and documenting a multiline substitution in Perl

I have recently been learning about the \x modifier in Perl Best Practices, enabling you to do cool things like multi-line indentation and documentation: $txt =~ m/^ # anchor at beginning of line The\ quick\ (\w+)\ fox #…
user1027562
  • 265
  • 4
  • 13
0
votes
3 answers

Struggling to perform string substitution within a nested for loop

In a Windows cmd shell batch script, I am trying to craft a mechanism to iterate over a series of directories which all have their name in the form of x.Year-Month-Day, where x is a sequential value, from 0 up to a defined limit. I want to…
0
votes
5 answers

Substite newlines with a string with awk

I need to parse stdin in the following way: (1) all newlines characters must be substituted with \n (a literal \ followed by n) (2) nothing else should be performed except the previous I chose awk to do it, and I would like an answer that uses awk…
robertspierre
  • 3,218
  • 2
  • 31
  • 46
0
votes
1 answer

sed substitution variable containing "/"

I've got a file containing information: eg: Hello START { toto=1 tata=2 } STOP I need to substitute what is between START and STOP by the content of a bash variable. This works well using sed \c but my variable contains the \ character that needs…
Totoc1001
  • 338
  • 2
  • 11
0
votes
1 answer

How do you change parts of a string with a list variable in a for loop?

I want to open many files to do an analysis through python. The title changes in three ways, ID, intervention and drug_type So I define the path where the files are and create three list variables which contain the names I want to swap parts of the…
Riss
  • 1
0
votes
3 answers

sequential column names add 0

I have a dataset with column names Col_a_b1 Col_a_b2 Col_a_b3 Col_a_b4 Col_a_b5 Col_a_b6 Col_a_b7 Col_a_b8 Col_a_b9 Col_a_b10 Col_a_b11 ... Col_a_b94 How do I add 0s to column names 1 to 10 , expected column names Col_a_b01 …
0
votes
3 answers

r remove keywords in a column

I have a column in my dataframe with words like this. ColA 2-4 Model Group1 Group ACH Group2 Phenols Group1 Group ACH Group2 MONO MHPP Group1 Group ACH Group2 I want to create two additional columns like this: 1) without keywords c("Group1", "Group…
0
votes
2 answers

How to change values before text in string using R

I have multiple strings that are similar to the following pattern: dat<-("00000000AAAAAAAAAA0AAAAAAAAAA0AAAAAAAAAAAAAAAAAAAAAAAAD0") I need to change all 0 values to "." before the first character value within a string. My desired output in this…
0
votes
1 answer

Replace Multiple Patterns in a String (Markdown Text)

I've read a bunch of answers regarding this topic but I'm convinced mine is a bit different given multiple pattern search and replace. Example: names = {'1234': 'John Doe', '2345': 'Jane Smith', '3456': 'Marry Jones' } …
dreamzboy
  • 795
  • 15
  • 31
0
votes
3 answers

substitute string when there is a dot + number + ':'

I have strings that look like these: > ABCD.1:f_HJK > ABFD.1:f_HTK > CJD:f_HRK > QQYP.2:f_HDP So basically, I have always a string in the first part, I could have a part with . and a number, and after this part I always have ':' and a string. I…
pingu87
  • 103
  • 6
0
votes
2 answers

Listing *.tif files in directories meeting certain criteria

I want to list all *.tif files in directories that contain specific numeric values. Example: Path_source <- "C:/Files/" Within this folder, I have 1000 folders, each named jobXXX where XXX stands for numeric value 1-999. So there is a folder job0,…
MIH
  • 1,083
  • 3
  • 14
  • 26
0
votes
1 answer

Eclipse: How to substitute strings in files copied to output folder

Eclipse copies files which are not Java sources to output folder as-is. I need to pre-process (substitute variables) these files before they are copied. The substitution table shall be project-based. Ideally, maven2 properties shall be used as the…
0
votes
1 answer

Complex text substitution algorithm or design pattern

I am in the need of doing multiple substitutions in a text coming from a database and before displaying it to the user. My example is for data most likely found on a CRM and the output is HTML for web, but the question is generalizable to any other…