I have a file like this
... 1562 first part 1563 H col3 H col4 1564 H col3 H col4 ... 3241 H col3 H col4 3242 third part ...
I want to replace only the first
H in every line to
# is its number of appearance. The output should be:
... 1562 first part 1563 H1 col3 H col4 1564 H2 col3 H col4 ... 3241 H1652 col3 H col4 3242 third part ...
So far, I've tried:
max=`grep -c ' H ' b` while [[ "$i" -le $max ]];do grep -m $i ' H ' b|tail -n1|sed "s/H/H$i/1" let i=i+1 done
This code is slow, it needs to read every line to replace and can't add the first part and third part of the file. Is there any better way to do this? Maybe awk? Thank you.