regex - Find pattern in line and replace where portion of pattern is evaluated in substitution -
I have a text line (new file format with bootstrap values) which has several numbers between 0.000 and 1.000 I want to multiply between 100 and 0 and 100 return values as a rounded integer. These numbers are all before "" and after that ":" There are other numbers in the line of text that I want to leave untouched, which are not surrounded by them. I'm trying to do it with Pearl One-liner:
perl -ape / s) (\ d \. \ D +): / \) int ($ 1 * 100 + .5): / e.g. Test.newick However, due to a syntax error it is failing, I believe because it is ")" and ":" Try to stay Any suggestions how can I do this? Thanks!
Some issues:
- A bracket is a regex special character.
- Your RHS needs to use string combinations, as it is being removed
- using Consider
'S { \] (\ D. \ D +):} {"}" .inte ($ 1 * 100 + .5) ":"} For example 'test.newick'
Alternatively, you can use letterhead And if you do not want to duplicate textual text in RHS, then pre> perl -ape 's {\) \ K (\ d. \ D +) (? = :)} {Int ($ 1 * 100 + .5)} Example 'test.newick
Comments
Post a Comment