Delete a lot of words with one command

You can use the "OR" syntax for regular expressions:

sed -E '/png|jpg|svg/d' url.txt

This will delete all lines containing either pattern. If you want to make sure that this pattern is the filename extension, i.e. that the pattern occurs at the end of the line, you can include an anchor into the regular expression:

sed -E '/(png|jpg|svg)$/d' url.txt

By the way, you never need to cat a file into sed; it can read them all on its own.


You can also use Grep:

grep -vE '\.(svg|jpg|png)' file

-v only prints non-matching lines and -E enables extended regex.

\.(svg|jpg|png) is the regex, that matches .svg or .jpg or .png.

If you want to modify the file,

  • Use Ed with the global command:

    printf '%s\n' 'g/\.\(svg\|jpg\|png\)/d' w q | ed -s file
    

    g is the global command, d deletes the matching lines, w saves the changes and q quits.

  • In a GNU/Linux system with Bash and Vim,

    vim -e file<<<'g/\v\.(svg|jpg|png)/d|x'
    

    g is the global command again, \v disables the need to escape the parenthesis, and x saves the changes.


grep is better suited.

Generate a pattern file, e.g.:

printf '\\.%s$\n' svg jpg png > patterns.txt

And remove lines with:

grep -vf patterns.txt url.txt

Or directly:

grep -ve "$(printf '\\.%s$\n' svg jpg png)" url.txt

Output:

https://content.example.net/skin/frontend/2015/default/fonts/test.ttf
https://content.example.net/skin/frontend/2015/default/fonts/test.eot
https://content.example.net/skin/forntend/2015/default/js/test.js