Split a file into multiple files based on a pattern and name the new files by the search pattern in Unix?

后端 未结 2 1654
慢半拍i
慢半拍i 2021-01-21 23:28

How can I split a file based on a search pattern and the new files that will be generated will have the file names as equal to the search pattern which was used to split the fil

2条回答
  •  感情败类
    2021-01-22 00:15

    Try:

    awk '/^GROUP[0-9]+$/{x=$0;next}{print > x;}' cdw_all_jobs_reduced3.txt
    

    If you want the "filenames" remove next statement:

    awk '/^GROUP[0-9]+$/{x=$0}{print > x;}' cdw_all_jobs_reduced3.txt
    

提交回复
热议问题