Create a gist now

Instantly share code, notes, and snippets.

@zunda /each-block.rb
Last active Feb 16, 2016

What would you like to do?
Run a command on each block in input file
# usage: ruby each-block.rb sertificate-bundle.crt openssl x509 -noout -text
require 'open3'
src = ARGV.shift
cmd = ARGV
input =
blocks = input.scan(/(^-+BEGIN (\w+)-+\R.*?\R-+END (\2)-+\R)/m).map{|e| e[0]}
blocks.each do |block|
Open3.pipeline_w(cmd) do |i|
i.print block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment