Search code examples
sedgrepshpcregrep

stripping out (ascii armored) PGP blocks in text file


given a file formatted as markdown occasionally interspersed with blocks of PGP, how can I strip out the PGP blocks using standard linux tools in a shell script?

The file looks like this gist

(I had to create a gist because of formatting issues)


Solution

  • Using sed you can do that:

    sed '/^-----BEGIN PGP/,/^-----END PGP/d' file
    

    In short: you define a range of lines between two patterns /pat1/,/pat2/ that are deleted (d).