Find and replace with sed in directory and sub directories
Your find should look like that to avoid sending directory names to sed: find ./ -type f -exec sed -i -e ‘s/apple/orange/g’ {} \;
Your find should look like that to avoid sending directory names to sed: find ./ -type f -exec sed -i -e ‘s/apple/orange/g’ {} \;
Even shorter than the :search command: :%norm A* This is what it means: % = for every line norm = type the following commands A* = append ‘*’ to the end of current line
Seems like string.Replace should have an overload that takes a StringComparison argument. Since it doesn’t, you could try something like this: public static string ReplaceString(string str, string oldValue, string newValue, StringComparison comparison) { StringBuilder sb = new StringBuilder(); int previousIndex = 0; int index = str.IndexOf(oldValue, comparison); while (index != -1) { sb.Append(str.Substring(previousIndex, index – … Read more
As pointed out by michaelb958, you cannot replace in place with data of a different length because this will put the rest of the sections out of place. I disagree with the other posters suggesting you read from one file and write to another. Instead, I would read the file into memory, fix the data … Read more
M-x replace-string RET ; RET C-q C-j. C-q for quoted-insert, C-j is a newline.
Try this: String after = before.trim().replaceAll(” +”, ” “); See also String.trim() Returns a copy of the string, with leading and trailing whitespace omitted. regular-expressions.info/Repetition No trim() regex It’s also possible to do this with just one replaceAll, but this is much less readable than the trim() solution. Nonetheless, it’s provided here just to show … Read more
With a regular expression and the function gsub(): group <- c(“12357e”, “12575e”, “197e18”, “e18947”) group [1] “12357e” “12575e” “197e18” “e18947” gsub(“e”, “”, group) [1] “12357” “12575” “19718” “18947” What gsub does here is to replace each occurrence of “e” with an empty string “”. See ?regexp or gsub for more help.
Another option is to use find and then pass it through sed. find /path/to/files -type f -exec sed -i ‘s/oldstring/new string/g’ {} \;
Maybe something like this: sed ‘s/ab/~~/g; s/bc/ab/g; s/~~/bc/g’ Replace ~ with a character that you know won’t be in the string.
Just use the String replace and toLowerCase methods, for example: var str = “Sonic Free Games”; str = str.replace(/\s+/g, ‘-‘).toLowerCase(); console.log(str); // “sonic-free-games” Notice the g flag on the RegExp, it will make the replacement globally within the string, if it’s not used, only the first occurrence will be replaced, and also, that RegExp will … Read more