Can't split a text file based on separator

后端 未结 2 1492
独厮守ぢ
独厮守ぢ 2021-01-26 06:51

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

---         


        
相关标签:
2条回答
  • 2021-01-26 07:18

    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)
    0 讨论(0)
  • 2021-01-26 07:29

    This should work:

    awk '/-----BEGIN PUBLIC KEY-----?/{n++}{print > "person_" n "_key" }' group_keys

    0 讨论(0)
提交回复
热议问题