#!/bin/bash
for N in aa bb cc ; do
ed -s $N <<EOF
P
# Make and mark a default line range for all potential addresses
$
a
== LAST 1 ==
== LAST 2 ==
.
-
ka
kb
kc
# Find and mark the real lines, if they exist
,g/aa/ka
,g/bb/kb
,g/cc/kc
# Go to each mark and append
'aa
AA
.
'ba
BB
.
'ca
CC
.
1
/== LAST 1 ==/
;d
w
q
EOF
done
