Closed alaws-USGS closed 1 year ago
@alaws-USGS - Do you know if we use this filepath in any notebooks or README's that we also need to update?
It would be nice to have a little script that runs through all the content on Github and does a string replacement (with supervision to say yes, replace). Do you or @gzt5142 have something that does this already? I could try to write it if you don't.
@amsnyder I wrote something to do this recently and could adapt it to this. Are you looking for the following on this PR:
@amsnyder I wrote something to do this recently and could adapt it to this. Are you looking for the following on this PR:
- Find instances of model_evaluation
- Replace model_evaluation with evaluation
- Resubmit for review
Yes! Just in case anything was pulled into a notebook like model_evaluation/Metrics_StdSuite_v1.ipynb
- we would need to update the filepath.
I was suggesting some kind of manual review of the changes in case it catches anything we actually didn't want to change - but perhaps we just look at the diff before requesting review on the PR.
Could you also add that script to this repo? maybe in doc
and I can just use what you've already pulled together to look for the CONUS404 catalog replacements? I imagine others might also need to use a script like this from time to time
@alaws-USGS - Do you know if we use this filepath in any notebooks or README's that we also need to update?
It would be nice to have a little script that runs through all the content on Github and does a string replacement (with supervision to say yes, replace). Do you or @gzt5142 have something that does this already? I could try to write it if you don't.
I do this with sed
from the command prompt. It isn't a supervised find/replace -- but a bulk stream edit.
# sed -I.bak -E "s/stringtofind/stringtoreplace/g" FileName.ipynb
You can name multiple files instead of just the single like I've shown here. The regex
pattern-matching capabilities of sed
are very powerful, so you can do a whole lot with it. Simple find/replace like this is pretty straightforward. The above command will save a backup copy (with a .bak
extension) before making edits.
To find all files in this folder and its sub-folders, doing the find/replace on each:
# find . -type f -name \*.ipynb -exec sed -I.bak -E "s/tofind/toreplace/g" {} \;
Now --- be careful with sed
. It is an excellent example of a tool that will do exactly what you tell it to do, not necessarily what you want it to do. Also... as notebooks are JSON text, sed will perform the replacement everywhere -- including in the metadata and output cells... not just the input cells.
--gt
One other thought --
If you just want to find the specific notebooks with the string of interest in it, use grep
. I do this if I want to go find the change myself to ensure the context, and that the change doesn't break anything. This command will tell me which files to go look for:
# find . -type f -name \*.ipynb grep -c stringtofind {} /dev/null \; | grep -v null
That will list all of the notebook files in this folder and all subs. each filename will be accompanied with a number indicating how many times it found stringtofind
in that file.
@gzt5142 I hadn't dealt with grep before so this is all a great learning experience for me! @amsnyder I didn't read the supervised part of your comment. I know you can also do this through the VSCode search bar, which is likely the easiest way to do it supervised. Otherwise, its identify notebooks through either CLI (@gzt5142) or script (@alaws-USGS) and do it manually or automatically.
@amsnyder I updated the filepaths with VSCode. Should be good!
@gzt5142 - would you open a new discussion for "bulk string replacement" and drop your tips in there? I'd like to keep that info around for reference!
@alaws-USGS - we lost a /
@amsnyder fixed!
@amsnyder good catches, added suggested changes
@gzt5142 - would you open a new discussion for "bulk string replacement" and drop your tips in there? I'd like to keep that info around for reference!
I see you already started one -- so I put a few more comments in that thread for the good of the order.
Closes #249