I\'m running Ubuntu 18.04 LTS. I have a text file named \"group_keys\", which contains a number of public keys that I\'d like to split based on the delimiter
---
Try
csplit -z -f person_ -b '%d_key' group_keys '/-----BEGIN PUBLIC KEY-----/' '{*}'
which would output four files person_0_key
, person_1_key
, person_2_key
, person_3_key
where
-z
suppresses the generation of empty files-f person_
sets the output filename prefix-b '%d_key'
sets the output filename suffix'{*}'
sets the repeat count (repeat as many times as possible)This should work:
awk '/-----BEGIN PUBLIC KEY-----?/{n++}{print > "person_" n "_key" }' group_keys