Let's say I got a file with three lines of this structure:
foo
Black sheep: 500
bar
What I'd like to do is an iteration to change "Black sheep: 500" to 600, 700 and so on, replacing the old one. I can think of a way of doing it by search&replace, but I'm looking for a more elegant way by replacing a certain position (here pos.3) within the line.
For example, in awk/shellscripting, it works like this:
cat filename | awk '$1 ~ /Black:/ { print ($1, $2, 600); next }; { print $0 }'
awk looks for "Black" in the file and prints the words number one, number two and 600 as well as the rest of the file.
Is there something similar in Python?
Thank you