I would like to change all occurrences like "waaa", "wwwaaaaa", "wa" by trimming all the "a" in the end.
waaa > w
wwa > ww
waaaaa > w
I know how to find these strings in a text using regular expressions:
grep -nE "wa+" file.txt
I also know how to change one string in a bash script
#!/bin/bash
s1="wwwwaaaaaaaa"
s2=${s1%w*}
echo "$s1 --> $s2"
(modified script from https://stackoverflow.com/a/27658717/5219155)
But I would like to use someting like
sed -E 's/wa+/ZZZ/' file.txt
where ZZZ is something that I need here.
sed -E 's/wa+/${$1%w*}/' file.txt
doesn't work.
Sample input:
Lorem ipsum wa waaaaaaa saaa dolor sit amet, consectetur aw awwwwaaaa adipiscing elit
Desirable output:
Lorem ipsum w w saaa dolor sit amet, consectetur aw awwww adipiscing elit