It depends on how you get the result of your external command but you might be interested in :h systemlist()
.
It executes the command given as parameter and returns a list containing every lines of the output. You can then use :h list-functions
on the result or simply listVar[1:]
.
I think that is more robust and portable than matching the lines and doing some substitutions.
Here is an example:
" Get the result of ls has a list
let output = systemlist('ls')
echo output " ['autoload', 'CODE_OF_CONDUCT.md', 'CONTRIBUTING.md', 'doc', 'plugin', 'README.md']
" Remove first line
let output = output[1:]
echo output " ['CODE_OF_CONDUCT.md', 'CONTRIBUTING.md', 'doc', 'plugin', 'README.md']
" Remove README.md
call filter(output, 'v:val != "README.md"')
echo output " ['CODE_OF_CONDUCT.md', 'CONTRIBUTING.md', 'doc', 'plugin']
" Remove all *.md files
call filter(output, 'v:val !~ ".md"')
echo output " ['doc', 'plugin']
See