Please take a look at PacketSmith available at packetsmith.ca, a comprehensive CLI utility for editing, transforming, and analyzing PCAP network traffic.
It does what you asked for, and much more.