python is too big a weapon for this. given: a. text.orig containing verse reference-less text. b. you're using bash. $ exec 17<text.orig $ mod2imp KJV | grep '^\$' | tr -d '$' | grep : | head -2 | while read key ; do read -u 17 line ; echo '$$$'"$key" "$line" ; done > text.vpl