I have a file which contains many links of the form <a href="foo">. These need to be given a .html extension, and I have the following command to do so:
sed -i 's/\(href="\)\([^"]*\)/\1\2.html/g' "$FILE"
However, I need to not do this on any link which has either a protocol (e.g. https:// or already has an extension (e.g. .css, .js—happy to match only these specifically.
How can I do this? Is sed still an appropriate tool here?
>Solution :
This sed may work.
$ sed -Ei.bak '/https|\.[a-z]+/!s/"[^"]*/&.html/' input_file
If not, please consider adding more information to the question.