When we match a pattern using sed, the matched pattern is stored in the \"ampersand\" (&) variable. IS there a way to replace a character in this matched pattern using the a
you can first match a pattern and then change the text if matched:
echo "apple1" | sed '/apple/s/1/2/' # gives you "apple2"
this code changes 1 to 2 in all lines containing apple
1
2
apple