I have plenty of Python2 files with pattern like this
datetime(2019, 04, 11)
datetime(2019, 10, 01)
datetime(2019, 04, 05, 1, 1)
To migrate this code into Python3 I have to remove leading 0 in 2nd and 3rd datetime argument.
I know how to use sed for simple patterns like this:
sed -e 's/01/1/g' -e 's/02/2/g' -e 's/03/3/g' my.py
But my pattern is more sophisticated: I should modify only 2nd and 3rd argument of datetime(). How to do it with sed or any other command-line tool?
The following command tries to find all strings to be modified in codebase with simple static pattern like this:
find . -name "*.py" | xargs grep datetime | grep '01\|02\|03\|04\|05\|06\|07'
But it also has the same problem as above: the grep pattern is not specific enough - the pattern above should not look at entire string, only on 2nd and 3rd argument of datetime().