Issue
i have some strings with this pattern in some files:
- domain.com/page-10
- domain.com/page-15 ....
and i want to replace them with something like
- domain.com/apple-10.html
- domain.com/apple-15.html
i have found that i can use sed command to replace them at a time but because after the numbers should something be added i guess i have to use regular expression to do it. but i don't know how.
Solution
sed -i.bak -r 's/page-([0-9]+)/apple-\1.html/' file
sed 's/page-\([0-9][0-9]*\)/apple-\1.html/' file > t && mv t file
Besides sed, you can also use gawk's gensub()
awk '{b=gensub(/page-([0-9]+)/,"apple-\\1.html","g",$0) ;print b }' file
Answered By - ghostdog74 Answer Checked By - Marilyn (WPSolving Volunteer)