How to substitute text from files in git history?

I’d recommend using the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch specifically designed for rewriting files from Git history. You should carefully follow these steps here: https://rtyley.github.io/bfg-repo-cleaner/#usage – but the core bit is just this: download the BFG’s jar (requires Java 7 or above) and run this command: $ java -jar bfg.jar –replace-text replacements.txt … Read more

sed substitution with Bash variables

Variables inside ‘ don’t get substituted in Bash. To get string substitution (or interpolation, if you’re familiar with Perl) you would need to change it to use double quotes ” instead of the single quotes: # Enclose the entire expression in double quotes $ sed “s/draw($prev_number;n_)/draw($number;n_)/g” file.txt > tmp # Or, concatenate strings with only … Read more

Java Variable Substitution

This is normally solved with just a String#replaceAll, but since you have a custom, dynamic replacement string, you can to use a Matcher to efficiently and concisely do the string replacement. public static String parse(String command, String… args) { StringBuffer sb = new StringBuffer(); Matcher m = Pattern.compile(“\\$(\\d+)”).matcher(command); while (m.find()) { int num = Integer.parseInt(m.group(1)); … Read more