4 ms·
wow I didn't know about the workspace file, replace directives are messy. It seems like I'm going to remove 149 replace directives of my own, what a nightmare.
by bithavoc 5y ago
wow I didn't know about the workspace file, replace directives are messy. It seems like I'm going to remove 149 replace directives of my own, what a nightmare.
grep -rnw '.' --include=\*.mod -e 'replace' | grep "" -c
149
- deleted 5y ago[deleted]
- akavel 5y agoNot 100% tested, but should hopefully work: find . -name go.mod | xargs gawk -i inplace '/^replace \(/{d=1}; (!d && !/^replace/); /^\)/{d=0}' Explanation of gawk arguments: — -i inplace — https://stackoverflow.com/a/16531920 https://stackoverflow.com/a/16531920 — /^replace \(/{d=1} — on lines starting with `replace (`, set a variable named `d` (any var name would work, 'd' is my mental shortcut for 'delete' here) to value `1` (i.e. "true"); Note: in awk, unset variables default to 0 ("false") value — (!d && !/^replace/) — on lines where `d` is 0 (which is default value of unset variables in awk), and which don't start with `replace` pattern, print the line. Default action when unspecified in awk is `{print}`, this entry is a shortcut of: (!d && !/^replace/) {print} — /^\)/{d=0} — on lines starting with `)`, reset `d` variable back to 0 ("false") In other words, this encodes: "delete any lines between `replace (` and nearest `)`, and also delete any other lines starting with `replace`"
- bithavoc 5y agoNice, learned a few things about awk here.